You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
3.0 KiB
75 lines
3.0 KiB
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
using X1.Application.Features.TaskExecution.Events.NodeExecutionEvents;
|
|
using X1.Domain.Events;
|
|
using X1.Domain.Entities.TestCase;
|
|
using X1.Domain.ServiceScope;
|
|
|
|
namespace X1.Application.Features.TaskExecution.Events.ControllerHandlers;
|
|
|
|
/// <summary>
|
|
/// 开启飞行模式控制器处理器
|
|
/// 处理开启飞行模式相关的节点执行事件
|
|
/// </summary>
|
|
public class EnableFlightModeControllerHandler : BaseControllerHandler, INotificationHandler<EnableFlightModeExecutionEvent>
|
|
{
|
|
|
|
public EnableFlightModeControllerHandler(
|
|
IMediator mediator,
|
|
ILogger<EnableFlightModeControllerHandler> logger,
|
|
IServiceScopeExecutor scopeExecutor)
|
|
: base(mediator, logger, scopeExecutor)
|
|
{
|
|
}
|
|
|
|
public async Task Handle(EnableFlightModeExecutionEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("开始执行开启飞行模式,任务执行ID: {TaskExecutionId}, 节点ID: {NodeId}",
|
|
notification.TaskExecutionId, notification.NodeId);
|
|
|
|
try
|
|
{
|
|
await UpdateNodeStatusAsync(notification.NodeId, NodeExecutionStatus.Running);
|
|
var result = await ExecuteEnableFlightModeAsync(notification, cancellationToken);
|
|
|
|
var executionResult = new NodeExecutionResult
|
|
{
|
|
TaskExecutionId = notification.TaskExecutionId,
|
|
NodeId = notification.NodeId,
|
|
StepMapping = StepMapping.EnableFlightMode,
|
|
Status = NodeExecutionStatus.Completed,
|
|
IsSuccess = true,
|
|
ResultData = result,
|
|
ExecutorId = notification.ExecutorId,
|
|
RuntimeCode = notification.RuntimeCode,
|
|
CreatedAt = DateTime.UtcNow
|
|
};
|
|
|
|
await PublishCompletedEventSafelyAsync(notification, executionResult, StepMapping.EnableFlightMode, cancellationToken);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "开启飞行模式执行失败,任务执行ID: {TaskExecutionId}, 节点ID: {NodeId}",
|
|
notification.TaskExecutionId, notification.NodeId);
|
|
await PublishFailedEventSafelyAsync(notification, ex.Message, "ENABLE_FLIGHT_MODE_ERROR", StepMapping.EnableFlightMode, cancellationToken);
|
|
}
|
|
}
|
|
|
|
private async Task<string> ExecuteEnableFlightModeAsync(EnableFlightModeExecutionEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("正在执行开启飞行模式,运行时编码: {RuntimeCode}", notification.RuntimeCode);
|
|
await Task.Delay(800, cancellationToken);
|
|
|
|
var result = new
|
|
{
|
|
Status = "Success",
|
|
Message = "飞行模式开启成功",
|
|
Timestamp = DateTime.UtcNow,
|
|
RuntimeCode = notification.RuntimeCode,
|
|
FlightModeEnabled = true
|
|
};
|
|
|
|
return System.Text.Json.JsonSerializer.Serialize(result);
|
|
}
|
|
|
|
}
|