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.
43 lines
1.3 KiB
43 lines
1.3 KiB
using Kean.Domain.Task.Commands;
|
|
using Kean.Domain.Task.Enums;
|
|
using Kean.Domain.Task.Repositories;
|
|
using System.Threading;
|
|
|
|
namespace Kean.Domain.Task.CommandHandlers
|
|
{
|
|
/// <summary>
|
|
/// 任务阻塞命令处理程序
|
|
/// </summary>
|
|
public sealed class BlockCommandHandler : CommandHandler<BlockCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly ITaskRepository _taskRepository; // 任务仓库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public BlockCommandHandler(
|
|
ICommandBus commandBus,
|
|
ITaskRepository taskRepository)
|
|
{
|
|
_commandBus = commandBus;
|
|
_taskRepository = taskRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async System.Threading.Tasks.Task Handle(BlockCommand command, CancellationToken cancellationToken)
|
|
{
|
|
if (command.ValidationResult.IsValid)
|
|
{
|
|
await _taskRepository.UpdateStatus(command.Id, TaskState.Blocked, command.Message);
|
|
}
|
|
else
|
|
{
|
|
await _commandBus.Notify(command.ValidationResult,
|
|
cancellationToken: cancellationToken);
|
|
}
|
|
}
|
|
}
|
|
}
|