From 635209133183900747996d241f400b2bf15e6bfb Mon Sep 17 00:00:00 2001 From: Dmitriy Krivopalov Date: Sat, 24 Feb 2024 14:14:31 +0300 Subject: [PATCH] Stage Handler exception (#55) * Task Exception processing * rector PHP 8.2 * fix style --- rector.php | 12 ++- src/EntityUuid.php | 4 +- src/EntityWrapper.php | 6 +- src/TaskBuilder.php | 4 +- src/TaskManagerOptions.php | 16 +-- src/TaskStageContext.php | 8 +- src/dto/StageModel.php | 18 ++-- src/dto/StageModelCreate.php | 12 +-- src/dto/TaskMetrics.php | 14 +-- src/dto/TaskModel.php | 18 ++-- src/dto/TaskOptions.php | 6 +- src/dto/TaskView.php | 18 ++-- src/event/ProcessTimeoutEvent.php | 6 +- src/handler/StageExecutor.php | 4 +- src/handler/StageHandler.php | 6 +- src/handler/StageHandlerFactory.php | 4 +- src/handler/TaskFinallyHandler.php | 4 +- src/processing/TaskHandler.php | 18 ++-- src/processing/TaskProcess.php | 10 +- src/processing/TaskProcessContext.php | 14 +-- src/processing/TaskProcessReady.php | 8 +- src/processing/TaskProcessing.php | 17 +-- src/service/TaskCreator.php | 10 +- src/service/TaskDestroyer.php | 6 +- src/service/TaskExecutor.php | 18 ++-- src/service/TaskViewer.php | 6 +- src/service/action/ActionCancel.php | 14 +-- src/service/action/ActionCompletion.php | 12 +-- src/service/action/ActionPause.php | 10 +- src/service/action/ActionReady.php | 6 +- src/service/action/ActionResume.php | 8 +- src/service/action/ActionRun.php | 8 +- src/service/action/ActionTerminate.php | 4 +- src/service/action/ActionWait.php | 8 +- src/state/TaskCommand.php | 4 +- src/state/TaskStateCanceled.php | 6 +- src/state/TaskStateDelay.php | 8 +- src/state/TaskStateError.php | 8 +- src/state/TaskStateMessage.php | 6 +- src/state/TaskStatePaused.php | 6 +- src/state/TaskStateRelation.php | 6 +- src/state/TaskStateRunning.php | 4 +- src/state/TaskStateSkip.php | 4 +- src/state/TaskStateSuccess.php | 6 +- src/state/TaskStateTerminate.php | 6 +- src/state/TaskStateWaiting.php | 10 +- src/state/response/ResponseWrapper.php | 6 +- src/tools/NodeServiceFactory.php | 4 +- src/tools/NullConsoleOutput.php | 4 +- src/tools/SerializerJson.php | 4 +- src/tools/TaskManagerOutput.php | 4 +- tests/ProcessingExceptionTest.php | 133 ++++++++++++++++++++++++ 52 files changed, 353 insertions(+), 213 deletions(-) create mode 100644 tests/ProcessingExceptionTest.php diff --git a/rector.php b/rector.php index 4b18166..ece97e7 100644 --- a/rector.php +++ b/rector.php @@ -23,9 +23,11 @@ $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); // define sets of rules - $rectorConfig->sets([ - SetList::CODE_QUALITY, - SetList::DEAD_CODE, - SetList::PHP_82, - ]); + $rectorConfig->sets( + [ + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + SetList::PHP_82, + ] + ); }; diff --git a/src/EntityUuid.php b/src/EntityUuid.php index 9b7bd65..8928d6e 100755 --- a/src/EntityUuid.php +++ b/src/EntityUuid.php @@ -6,12 +6,12 @@ use Ramsey\Uuid\Uuid; -final class EntityUuid +final readonly class EntityUuid { /** * @var non-empty-string */ - private readonly string $uuid; + private string $uuid; /** * @param non-empty-string|null $uuid diff --git a/src/EntityWrapper.php b/src/EntityWrapper.php index a8de3d6..22cbce0 100644 --- a/src/EntityWrapper.php +++ b/src/EntityWrapper.php @@ -7,15 +7,15 @@ use Serializable; use kuaukutsu\poc\task\exception\UnsupportedException; -final class EntityWrapper implements Serializable +final readonly class EntityWrapper implements Serializable { /** * @param class-string $class * @param array $params Конфигурация объекта. */ public function __construct( - public readonly string $class, - public readonly array $params = [], + public string $class, + public array $params = [], ) { } diff --git a/src/TaskBuilder.php b/src/TaskBuilder.php index 4a06397..e515251 100755 --- a/src/TaskBuilder.php +++ b/src/TaskBuilder.php @@ -8,9 +8,9 @@ use kuaukutsu\poc\task\exception\BuilderException; use kuaukutsu\poc\task\service\TaskCreator; -final class TaskBuilder +final readonly class TaskBuilder { - public function __construct(private readonly TaskCreator $creator) + public function __construct(private TaskCreator $creator) { } diff --git a/src/TaskManagerOptions.php b/src/TaskManagerOptions.php index 0c536eb..d76e215 100755 --- a/src/TaskManagerOptions.php +++ b/src/TaskManagerOptions.php @@ -4,7 +4,7 @@ namespace kuaukutsu\poc\task; -final class TaskManagerOptions +final readonly class TaskManagerOptions { /** * @param float $heartbeat in Seconds @@ -13,13 +13,13 @@ final class TaskManagerOptions * @param int[] $interruptSignals A POSIX signal */ public function __construct( - private readonly ?string $bindir = null, - private readonly float $heartbeat = 30., - private readonly float $keeperInterval = 5., - private readonly int $queueSize = 10, - public readonly ?float $timeout = null, - public readonly string $handler = 'handler.php', - public readonly array $interruptSignals = [SIGHUP, SIGINT, SIGTERM], + private ?string $bindir = null, + private float $heartbeat = 30., + private float $keeperInterval = 5., + private int $queueSize = 10, + public ?float $timeout = null, + public string $handler = 'handler.php', + public array $interruptSignals = [SIGHUP, SIGINT, SIGTERM], ) { } diff --git a/src/TaskStageContext.php b/src/TaskStageContext.php index f305034..1bac8dc 100644 --- a/src/TaskStageContext.php +++ b/src/TaskStageContext.php @@ -6,16 +6,16 @@ use kuaukutsu\poc\task\state\TaskStateInterface; -final class TaskStageContext +final readonly class TaskStageContext { /** * @param non-empty-string $task * @param non-empty-string $stage */ public function __construct( - public readonly string $task, - public readonly string $stage, - public readonly ?TaskStateInterface $previous = null, + public string $task, + public string $stage, + public ?TaskStateInterface $previous = null, ) { } } diff --git a/src/dto/StageModel.php b/src/dto/StageModel.php index cd4c71f..c376c9e 100755 --- a/src/dto/StageModel.php +++ b/src/dto/StageModel.php @@ -9,7 +9,7 @@ /** * @readonly */ -final class StageModel implements EntityArrable +final readonly class StageModel implements EntityArrable { /** * @param non-empty-string $uuid @@ -19,14 +19,14 @@ final class StageModel implements EntityArrable * @param non-empty-string $updatedAt */ public function __construct( - public readonly string $uuid, - public readonly string $taskUuid, - public readonly int $flag, - public readonly string $state, - public readonly string $handler, - public readonly int $order, - public readonly string $createdAt, - public readonly string $updatedAt, + public string $uuid, + public string $taskUuid, + public int $flag, + public string $state, + public string $handler, + public int $order, + public string $createdAt, + public string $updatedAt, ) { } diff --git a/src/dto/StageModelCreate.php b/src/dto/StageModelCreate.php index c744856..6221152 100644 --- a/src/dto/StageModelCreate.php +++ b/src/dto/StageModelCreate.php @@ -9,14 +9,14 @@ /** * @readonly */ -final class StageModelCreate implements EntityArrable +final readonly class StageModelCreate implements EntityArrable { public function __construct( - public readonly string $taskUuid, - public readonly int $flag, - public readonly string $state, - public readonly string $handler, - public readonly int $order, + public string $taskUuid, + public int $flag, + public string $state, + public string $handler, + public int $order, ) { } diff --git a/src/dto/TaskMetrics.php b/src/dto/TaskMetrics.php index 0ea8de7..dfb5f60 100644 --- a/src/dto/TaskMetrics.php +++ b/src/dto/TaskMetrics.php @@ -6,15 +6,15 @@ use kuaukutsu\poc\task\EntityArrable; -final class TaskMetrics implements EntityArrable +final readonly class TaskMetrics implements EntityArrable { public function __construct( - public readonly int $count = 0, - public readonly int $running = 0, - public readonly int $waiting = 0, - public readonly int $success = 0, - public readonly int $canceled = 0, - public readonly int $failed = 0, + public int $count = 0, + public int $running = 0, + public int $waiting = 0, + public int $success = 0, + public int $canceled = 0, + public int $failed = 0, ) { } diff --git a/src/dto/TaskModel.php b/src/dto/TaskModel.php index 7baffd5..6708b0e 100755 --- a/src/dto/TaskModel.php +++ b/src/dto/TaskModel.php @@ -9,7 +9,7 @@ /** * @readonly */ -final class TaskModel implements EntityArrable +final readonly class TaskModel implements EntityArrable { /** * @param non-empty-string $uuid @@ -20,14 +20,14 @@ final class TaskModel implements EntityArrable * @param non-empty-string $updatedAt */ public function __construct( - public readonly string $uuid, - public readonly string $title, - public readonly int $flag, - public readonly string $state, - public readonly array $options, - public readonly string $checksum, - public readonly string $createdAt, - public readonly string $updatedAt, + public string $uuid, + public string $title, + public int $flag, + public string $state, + public array $options, + public string $checksum, + public string $createdAt, + public string $updatedAt, ) { } diff --git a/src/dto/TaskOptions.php b/src/dto/TaskOptions.php index 3365f8d..cc99a8f 100644 --- a/src/dto/TaskOptions.php +++ b/src/dto/TaskOptions.php @@ -10,15 +10,15 @@ /** * @readonly */ -final class TaskOptions implements EntityArrable +final readonly class TaskOptions implements EntityArrable { /** * @param float $timeout В секундах. * @param class-string|null $finally */ public function __construct( - public readonly float $timeout, - public readonly ?string $finally = null, + public float $timeout, + public ?string $finally = null, ) { } diff --git a/src/dto/TaskView.php b/src/dto/TaskView.php index 297d4da..d72737d 100755 --- a/src/dto/TaskView.php +++ b/src/dto/TaskView.php @@ -9,17 +9,17 @@ /** * @readonly */ -final class TaskView implements EntityArrable +final readonly class TaskView implements EntityArrable { public function __construct( - public readonly string $uuid, - public readonly string $title, - public readonly string $state, - public readonly string $message, - public readonly TaskMetrics $metrics, - public readonly ?TaskView $relation, - public readonly string $createdAt, - public readonly string $updatedAt, + public string $uuid, + public string $title, + public string $state, + public string $message, + public TaskMetrics $metrics, + public ?TaskView $relation, + public string $createdAt, + public string $updatedAt, ) { } diff --git a/src/event/ProcessTimeoutEvent.php b/src/event/ProcessTimeoutEvent.php index 94d5ad2..eef87f6 100644 --- a/src/event/ProcessTimeoutEvent.php +++ b/src/event/ProcessTimeoutEvent.php @@ -7,11 +7,11 @@ use kuaukutsu\poc\task\processing\TaskProcess; use Symfony\Component\Process\Process; -final class ProcessTimeoutEvent implements EventInterface +final readonly class ProcessTimeoutEvent implements EventInterface { public function __construct( - private readonly TaskProcess $process, - private readonly string $message, + private TaskProcess $process, + private string $message, ) { } diff --git a/src/handler/StageExecutor.php b/src/handler/StageExecutor.php index 1561782..37a6006 100644 --- a/src/handler/StageExecutor.php +++ b/src/handler/StageExecutor.php @@ -12,9 +12,9 @@ use kuaukutsu\poc\task\state\TaskStateMessage; use kuaukutsu\poc\task\TaskStageContext; -final class StageExecutor +final readonly class StageExecutor { - public function __construct(private readonly StageHandlerFactory $handlerFactory) + public function __construct(private StageHandlerFactory $handlerFactory) { } diff --git a/src/handler/StageHandler.php b/src/handler/StageHandler.php index 9b34404..5f8883b 100755 --- a/src/handler/StageHandler.php +++ b/src/handler/StageHandler.php @@ -12,11 +12,11 @@ use kuaukutsu\poc\task\state\TaskStateSuccess; use kuaukutsu\poc\task\state\TaskCommand; -final class StageHandler +final readonly class StageHandler { public function __construct( - private readonly TaskHandler $handler, - private readonly ConsoleOutputInterface $output, + private TaskHandler $handler, + private ConsoleOutputInterface $output, ) { } diff --git a/src/handler/StageHandlerFactory.php b/src/handler/StageHandlerFactory.php index c9c093f..3612c99 100755 --- a/src/handler/StageHandlerFactory.php +++ b/src/handler/StageHandlerFactory.php @@ -13,9 +13,9 @@ use kuaukutsu\poc\task\EntityWrapper; use kuaukutsu\poc\task\exception\BuilderException; -final class StageHandlerFactory +final readonly class StageHandlerFactory { - public function __construct(private readonly FactoryInterface $container) + public function __construct(private FactoryInterface $container) { } diff --git a/src/handler/TaskFinallyHandler.php b/src/handler/TaskFinallyHandler.php index b8f8c28..d716a63 100644 --- a/src/handler/TaskFinallyHandler.php +++ b/src/handler/TaskFinallyHandler.php @@ -14,11 +14,11 @@ use kuaukutsu\poc\task\state\TaskStatePrepare; use kuaukutsu\poc\task\EntityFinally; -final class TaskFinallyHandler +final readonly class TaskFinallyHandler { use TaskStatePrepare; - public function __construct(private readonly ContainerInterface $container) + public function __construct(private ContainerInterface $container) { } diff --git a/src/processing/TaskHandler.php b/src/processing/TaskHandler.php index 4152dc3..f5fa165 100644 --- a/src/processing/TaskHandler.php +++ b/src/processing/TaskHandler.php @@ -24,17 +24,17 @@ use kuaukutsu\poc\task\EntityTask; use kuaukutsu\poc\task\EntityUuid; -final class TaskHandler +final readonly class TaskHandler { public function __construct( - private readonly TaskQuery $taskQuery, - private readonly TaskFactory $taskFactory, - private readonly TaskExecutor $taskExecutor, - private readonly TaskFinallyHandler $finallyHandler, - private readonly StageQuery $stageQuery, - private readonly StageCommand $stageCommand, - private readonly StageContextFactory $contextFactory, - private readonly StageExecutor $executor, + private TaskQuery $taskQuery, + private TaskFactory $taskFactory, + private TaskExecutor $taskExecutor, + private TaskFinallyHandler $finallyHandler, + private StageQuery $stageQuery, + private StageCommand $stageCommand, + private StageContextFactory $contextFactory, + private StageExecutor $executor, ) { } diff --git a/src/processing/TaskProcess.php b/src/processing/TaskProcess.php index f231dca..f5ef3d3 100644 --- a/src/processing/TaskProcess.php +++ b/src/processing/TaskProcess.php @@ -11,7 +11,7 @@ /** * Process Decorator. */ -final class TaskProcess +final readonly class TaskProcess { /** * @see https://tldp.org/LDP/abs/html/exitcodes.html @@ -25,10 +25,10 @@ final class TaskProcess * @param non-empty-string $stage */ public function __construct( - public readonly string $hash, - public readonly string $task, - public readonly string $stage, - private readonly Process $process, + public string $hash, + public string $task, + public string $stage, + private Process $process, ) { } diff --git a/src/processing/TaskProcessContext.php b/src/processing/TaskProcessContext.php index 3153033..e8f4f12 100755 --- a/src/processing/TaskProcessContext.php +++ b/src/processing/TaskProcessContext.php @@ -6,12 +6,12 @@ use kuaukutsu\poc\task\dto\TaskOptions; -final class TaskProcessContext +final readonly class TaskProcessContext { /** * @var non-empty-string */ - private readonly string $hash; + private string $hash; /** * @param non-empty-string $task Task UUID @@ -20,11 +20,11 @@ final class TaskProcessContext * @param positive-int|null $timestamp Примерное время (Unix) не раньше которого задача должна быть выполнена. */ public function __construct( - public readonly string $task, - public readonly string $stage, - public readonly TaskOptions $options, - public readonly ?string $previous = null, - public readonly ?int $timestamp = null, + public string $task, + public string $stage, + public TaskOptions $options, + public ?string $previous = null, + public ?int $timestamp = null, ) { $this->hash = hash('crc32b', $this->task . $this->stage); } diff --git a/src/processing/TaskProcessReady.php b/src/processing/TaskProcessReady.php index 30d0913..e6fb152 100644 --- a/src/processing/TaskProcessReady.php +++ b/src/processing/TaskProcessReady.php @@ -18,16 +18,16 @@ use kuaukutsu\poc\task\EntityTask; use kuaukutsu\poc\task\EntityUuid; -final class TaskProcessReady +final readonly class TaskProcessReady { /** * @var SplQueue $queue */ - private readonly SplQueue $queue; + private SplQueue $queue; public function __construct( - private readonly StageQuery $query, - private readonly StageCommand $command, + private StageQuery $query, + private StageCommand $command, ) { $this->queue = new SplQueue(); } diff --git a/src/processing/TaskProcessing.php b/src/processing/TaskProcessing.php index 808d272..92440f5 100644 --- a/src/processing/TaskProcessing.php +++ b/src/processing/TaskProcessing.php @@ -16,14 +16,14 @@ use kuaukutsu\poc\task\EntityTask; use kuaukutsu\poc\task\EntityUuid; -final class TaskProcessing +final readonly class TaskProcessing { public function __construct( - private readonly TaskQuery $taskQuery, - private readonly TaskFactory $taskFactory, - private readonly TaskExecutor $taskExecutor, - private readonly TaskProcessReady $processReady, - private readonly StateFactory $stateFactory, + private TaskQuery $taskQuery, + private TaskFactory $taskFactory, + private TaskExecutor $taskExecutor, + private TaskProcessReady $processReady, + private StateFactory $stateFactory, ) { } @@ -89,6 +89,11 @@ public function next(TaskProcess $process): void return; } + if ($process->isSuccessful() === false) { + $this->cancel($process); + return; + } + $state = $this->stateFactory->create( $process->task, $process->getOutput(), diff --git a/src/service/TaskCreator.php b/src/service/TaskCreator.php index 0fb6a53..0a4ea88 100755 --- a/src/service/TaskCreator.php +++ b/src/service/TaskCreator.php @@ -19,13 +19,13 @@ use kuaukutsu\poc\task\TaskStageContext; use kuaukutsu\poc\task\TaskDraft; -final class TaskCreator +final readonly class TaskCreator { public function __construct( - private readonly TaskQuery $taskQuery, - private readonly TaskCommand $taskCommand, - private readonly StageCommand $stageCommand, - private readonly TaskFactory $factory, + private TaskQuery $taskQuery, + private TaskCommand $taskCommand, + private StageCommand $stageCommand, + private TaskFactory $factory, ) { } diff --git a/src/service/TaskDestroyer.php b/src/service/TaskDestroyer.php index 98919a8..921ff89 100644 --- a/src/service/TaskDestroyer.php +++ b/src/service/TaskDestroyer.php @@ -8,11 +8,11 @@ use kuaukutsu\poc\task\exception\NotFoundException; use kuaukutsu\poc\task\EntityUuid; -final class TaskDestroyer +final readonly class TaskDestroyer { public function __construct( - private readonly TaskCommand $taskCommand, - private readonly StageCommand $stageCommand, + private TaskCommand $taskCommand, + private StageCommand $stageCommand, ) { } diff --git a/src/service/TaskExecutor.php b/src/service/TaskExecutor.php index f4e99de..8a90822 100644 --- a/src/service/TaskExecutor.php +++ b/src/service/TaskExecutor.php @@ -15,17 +15,17 @@ use kuaukutsu\poc\task\state\TaskStateInterface; use kuaukutsu\poc\task\EntityTask; -final class TaskExecutor +final readonly class TaskExecutor { public function __construct( - private readonly ActionCancel $actionCancel, - private readonly ActionCompletion $actionCompletion, - private readonly ActionPause $actionPause, - private readonly ActionReady $actionReady, - private readonly ActionResume $actionResume, - private readonly ActionRun $actionRun, - private readonly ActionWait $actionWait, - private readonly ActionTerminate $actionTerminate, + private ActionCancel $actionCancel, + private ActionCompletion $actionCompletion, + private ActionPause $actionPause, + private ActionReady $actionReady, + private ActionResume $actionResume, + private ActionRun $actionRun, + private ActionWait $actionWait, + private ActionTerminate $actionTerminate, ) { } diff --git a/src/service/TaskViewer.php b/src/service/TaskViewer.php index bf9d52d..acefa17 100644 --- a/src/service/TaskViewer.php +++ b/src/service/TaskViewer.php @@ -13,13 +13,13 @@ use kuaukutsu\poc\task\state\TaskStatePrepare; use kuaukutsu\poc\task\EntityUuid; -final class TaskViewer +final readonly class TaskViewer { use TaskStatePrepare; public function __construct( - private readonly TaskQuery $taskQuery, - private readonly StageQuery $stageQuery, + private TaskQuery $taskQuery, + private StageQuery $stageQuery, ) { } diff --git a/src/service/action/ActionCancel.php b/src/service/action/ActionCancel.php index 704e9d9..c9c76a6 100644 --- a/src/service/action/ActionCancel.php +++ b/src/service/action/ActionCancel.php @@ -17,13 +17,13 @@ use kuaukutsu\poc\task\EntityUuid; use kuaukutsu\poc\task\EntityTask; -final class ActionCancel implements TaskAction +final readonly class ActionCancel implements TaskAction { public function __construct( - private readonly StageCommand $stageCommand, - private readonly TaskCommand $taskCommand, - private readonly TaskFactory $factory, - private readonly TransitionState $transition, + private StageCommand $stageCommand, + private TaskCommand $taskCommand, + private TaskFactory $factory, + private TransitionState $transition, ) { } @@ -33,8 +33,8 @@ public function execute(EntityTask $task, ?TaskStateInterface $state = null): En return $task; } - $state ??= new TaskStateCanceled( - message: new TaskStateMessage('Task Canceled.'), + $state = new TaskStateCanceled( + message: $state?->getMessage() ?? new TaskStateMessage('Task Canceled.'), flag: $task->getFlag(), ); diff --git a/src/service/action/ActionCompletion.php b/src/service/action/ActionCompletion.php index b5e0212..f4fac93 100644 --- a/src/service/action/ActionCompletion.php +++ b/src/service/action/ActionCompletion.php @@ -21,14 +21,14 @@ use kuaukutsu\poc\task\EntityUuid; use kuaukutsu\poc\task\TaskResponseInterface; -final class ActionCompletion implements TaskAction +final readonly class ActionCompletion implements TaskAction { public function __construct( - private readonly StageQuery $stageQuery, - private readonly StageCommand $stageCommand, - private readonly StateFactory $stateFactory, - private readonly TaskCommand $taskCommand, - private readonly TaskFactory $factory, + private StageQuery $stageQuery, + private StageCommand $stageCommand, + private StateFactory $stateFactory, + private TaskCommand $taskCommand, + private TaskFactory $factory, ) { } diff --git a/src/service/action/ActionPause.php b/src/service/action/ActionPause.php index 565ab84..75e20fc 100644 --- a/src/service/action/ActionPause.php +++ b/src/service/action/ActionPause.php @@ -17,13 +17,13 @@ use kuaukutsu\poc\task\EntityUuid; use kuaukutsu\poc\task\EntityTask; -final class ActionPause implements TaskAction +final readonly class ActionPause implements TaskAction { public function __construct( - private readonly StageCommand $stageCommand, - private readonly TaskCommand $taskCommand, - private readonly TaskFactory $factory, - private readonly TransitionState $transition, + private StageCommand $stageCommand, + private TaskCommand $taskCommand, + private TaskFactory $factory, + private TransitionState $transition, ) { } diff --git a/src/service/action/ActionReady.php b/src/service/action/ActionReady.php index a375428..672b1b0 100644 --- a/src/service/action/ActionReady.php +++ b/src/service/action/ActionReady.php @@ -12,11 +12,11 @@ use kuaukutsu\poc\task\EntityTask; use kuaukutsu\poc\task\EntityUuid; -final class ActionReady implements TaskAction +final readonly class ActionReady implements TaskAction { public function __construct( - private readonly TaskCommand $command, - private readonly TaskFactory $factory, + private TaskCommand $command, + private TaskFactory $factory, ) { } diff --git a/src/service/action/ActionResume.php b/src/service/action/ActionResume.php index aa70d06..2f3c9a5 100644 --- a/src/service/action/ActionResume.php +++ b/src/service/action/ActionResume.php @@ -13,12 +13,12 @@ use kuaukutsu\poc\task\EntityTask; use kuaukutsu\poc\task\EntityUuid; -final class ActionResume implements TaskAction +final readonly class ActionResume implements TaskAction { public function __construct( - private readonly TaskCommand $command, - private readonly TaskFactory $factory, - private readonly TransitionState $transition, + private TaskCommand $command, + private TaskFactory $factory, + private TransitionState $transition, ) { } diff --git a/src/service/action/ActionRun.php b/src/service/action/ActionRun.php index 98852d9..ea924a5 100644 --- a/src/service/action/ActionRun.php +++ b/src/service/action/ActionRun.php @@ -13,12 +13,12 @@ use kuaukutsu\poc\task\EntityUuid; use kuaukutsu\poc\task\EntityTask; -final class ActionRun implements TaskAction +final readonly class ActionRun implements TaskAction { public function __construct( - private readonly TaskCommand $command, - private readonly TaskFactory $factory, - private readonly TransitionState $transition, + private TaskCommand $command, + private TaskFactory $factory, + private TransitionState $transition, ) { } diff --git a/src/service/action/ActionTerminate.php b/src/service/action/ActionTerminate.php index 1b15130..c44a4f1 100644 --- a/src/service/action/ActionTerminate.php +++ b/src/service/action/ActionTerminate.php @@ -9,9 +9,9 @@ use kuaukutsu\poc\task\state\TaskStateTerminate; use kuaukutsu\poc\task\service\TaskCommand; -final class ActionTerminate +final readonly class ActionTerminate { - public function __construct(private readonly TaskCommand $command) + public function __construct(private TaskCommand $command) { } diff --git a/src/service/action/ActionWait.php b/src/service/action/ActionWait.php index 5902eab..75b7659 100644 --- a/src/service/action/ActionWait.php +++ b/src/service/action/ActionWait.php @@ -12,12 +12,12 @@ use kuaukutsu\poc\task\EntityTask; use kuaukutsu\poc\task\EntityUuid; -final class ActionWait implements TaskAction +final readonly class ActionWait implements TaskAction { public function __construct( - private readonly TaskCommand $command, - private readonly TaskFactory $factory, - private readonly TransitionState $transition, + private TaskCommand $command, + private TaskFactory $factory, + private TransitionState $transition, ) { } diff --git a/src/state/TaskCommand.php b/src/state/TaskCommand.php index 8a9ce30..e656c6e 100644 --- a/src/state/TaskCommand.php +++ b/src/state/TaskCommand.php @@ -6,7 +6,7 @@ use Stringable; -final class TaskCommand implements Stringable +final readonly class TaskCommand implements Stringable { private const COMMAND_NULL = '00000000-0000-0000-0000-000000000000'; private const COMMAND_STOP = '00000000-0000-0000-0000-000000000001'; @@ -14,7 +14,7 @@ final class TaskCommand implements Stringable /** * @param non-empty-string $command */ - public function __construct(private readonly string $command = self::COMMAND_NULL) + public function __construct(private string $command = self::COMMAND_NULL) { } diff --git a/src/state/TaskStateCanceled.php b/src/state/TaskStateCanceled.php index c4e3066..39b2d9d 100755 --- a/src/state/TaskStateCanceled.php +++ b/src/state/TaskStateCanceled.php @@ -6,13 +6,13 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateCanceled implements TaskStateInterface +final readonly class TaskStateCanceled implements TaskStateInterface { use TaskStateSerialize; public function __construct( - private readonly TaskStateMessage $message, - private readonly int $flag = 0, + private TaskStateMessage $message, + private int $flag = 0, ) { } diff --git a/src/state/TaskStateDelay.php b/src/state/TaskStateDelay.php index b2d0b90..120790f 100755 --- a/src/state/TaskStateDelay.php +++ b/src/state/TaskStateDelay.php @@ -6,7 +6,7 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateDelay implements TaskStateInterface +final readonly class TaskStateDelay implements TaskStateInterface { use TaskStateSerialize; @@ -19,9 +19,9 @@ final class TaskStateDelay implements TaskStateInterface * @param positive-int $delay Second */ public function __construct( - public readonly string $uuid, - public readonly int $delay, - public readonly int $flag, + public string $uuid, + public int $delay, + public int $flag, ) { } diff --git a/src/state/TaskStateError.php b/src/state/TaskStateError.php index 3f57f47..9d9b05d 100755 --- a/src/state/TaskStateError.php +++ b/src/state/TaskStateError.php @@ -6,14 +6,14 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateError implements TaskStateInterface +final readonly class TaskStateError implements TaskStateInterface { use TaskStateSerialize; public function __construct( - private readonly TaskStateMessage $message, - private readonly int $flag = 0, - private readonly ?TaskResponseInterface $response = null, + private TaskStateMessage $message, + private int $flag = 0, + private ?TaskResponseInterface $response = null, ) { } diff --git a/src/state/TaskStateMessage.php b/src/state/TaskStateMessage.php index 218d4a4..1bc96e4 100755 --- a/src/state/TaskStateMessage.php +++ b/src/state/TaskStateMessage.php @@ -6,13 +6,13 @@ use Serializable; -final class TaskStateMessage implements Serializable +final readonly class TaskStateMessage implements Serializable { use TaskStateSerialize; public function __construct( - public readonly string $message, - public readonly ?string $description = null, + public string $message, + public ?string $description = null, ) { } } diff --git a/src/state/TaskStatePaused.php b/src/state/TaskStatePaused.php index fcbefba..89b5eff 100755 --- a/src/state/TaskStatePaused.php +++ b/src/state/TaskStatePaused.php @@ -6,13 +6,13 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStatePaused implements TaskStateInterface +final readonly class TaskStatePaused implements TaskStateInterface { use TaskStateSerialize; public function __construct( - private readonly TaskStateMessage $message, - private readonly int $flag = 0, + private TaskStateMessage $message, + private int $flag = 0, ) { } diff --git a/src/state/TaskStateRelation.php b/src/state/TaskStateRelation.php index b3d54c4..d170423 100755 --- a/src/state/TaskStateRelation.php +++ b/src/state/TaskStateRelation.php @@ -6,7 +6,7 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateRelation implements TaskStateInterface +final readonly class TaskStateRelation implements TaskStateInterface { use TaskStateSerialize; @@ -15,8 +15,8 @@ final class TaskStateRelation implements TaskStateInterface * @param non-empty-string $stage StageRelation::UUID */ public function __construct( - public readonly string $task, - public readonly string $stage, + public string $task, + public string $stage, ) { } diff --git a/src/state/TaskStateRunning.php b/src/state/TaskStateRunning.php index 9d43655..36fca86 100755 --- a/src/state/TaskStateRunning.php +++ b/src/state/TaskStateRunning.php @@ -6,11 +6,11 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateRunning implements TaskStateInterface +final readonly class TaskStateRunning implements TaskStateInterface { use TaskStateSerialize; - public function __construct(private readonly TaskStateMessage $message) + public function __construct(private TaskStateMessage $message) { } diff --git a/src/state/TaskStateSkip.php b/src/state/TaskStateSkip.php index 61590cd..0360efc 100755 --- a/src/state/TaskStateSkip.php +++ b/src/state/TaskStateSkip.php @@ -6,11 +6,11 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateSkip implements TaskStateInterface +final readonly class TaskStateSkip implements TaskStateInterface { use TaskStateSerialize; - public function __construct(private readonly TaskStateMessage $message) + public function __construct(private TaskStateMessage $message) { } diff --git a/src/state/TaskStateSuccess.php b/src/state/TaskStateSuccess.php index 5834bcd..0b4e9c0 100755 --- a/src/state/TaskStateSuccess.php +++ b/src/state/TaskStateSuccess.php @@ -6,13 +6,13 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateSuccess implements TaskStateInterface +final readonly class TaskStateSuccess implements TaskStateInterface { use TaskStateSerialize; public function __construct( - private readonly TaskStateMessage $message, - private readonly ?TaskResponseInterface $response = null, + private TaskStateMessage $message, + private ?TaskResponseInterface $response = null, ) { } diff --git a/src/state/TaskStateTerminate.php b/src/state/TaskStateTerminate.php index cc39baf..e3b382c 100755 --- a/src/state/TaskStateTerminate.php +++ b/src/state/TaskStateTerminate.php @@ -6,13 +6,13 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateTerminate implements TaskStateInterface +final readonly class TaskStateTerminate implements TaskStateInterface { use TaskStateSerialize; public function __construct( - private readonly TaskStateMessage $message, - private readonly int $flag = 0, + private TaskStateMessage $message, + private int $flag = 0, ) { } diff --git a/src/state/TaskStateWaiting.php b/src/state/TaskStateWaiting.php index 8bf755a..2895a1e 100755 --- a/src/state/TaskStateWaiting.php +++ b/src/state/TaskStateWaiting.php @@ -6,7 +6,7 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class TaskStateWaiting implements TaskStateInterface +final readonly class TaskStateWaiting implements TaskStateInterface { use TaskStateSerialize; @@ -15,10 +15,10 @@ final class TaskStateWaiting implements TaskStateInterface * @param non-empty-string $task TaskRelation::UUID */ public function __construct( - public readonly string $uuid, - public readonly string $task, - private readonly TaskStateMessage $message, - private readonly ?TaskResponseInterface $response = null, + public string $uuid, + public string $task, + private TaskStateMessage $message, + private ?TaskResponseInterface $response = null, ) { } diff --git a/src/state/response/ResponseWrapper.php b/src/state/response/ResponseWrapper.php index 8e463b6..c3c88e1 100644 --- a/src/state/response/ResponseWrapper.php +++ b/src/state/response/ResponseWrapper.php @@ -6,14 +6,14 @@ use kuaukutsu\poc\task\TaskResponseInterface; -final class ResponseWrapper +final readonly class ResponseWrapper { /** * @param class-string $class */ public function __construct( - public readonly string $class, - public readonly string $serializeData, + public string $class, + public string $serializeData, ) { } } diff --git a/src/tools/NodeServiceFactory.php b/src/tools/NodeServiceFactory.php index fdf6ef8..3ab718c 100644 --- a/src/tools/NodeServiceFactory.php +++ b/src/tools/NodeServiceFactory.php @@ -11,9 +11,9 @@ /** * @template T */ -final class NodeServiceFactory +final readonly class NodeServiceFactory { - public function __construct(private readonly FactoryInterface $factory) + public function __construct(private FactoryInterface $factory) { } diff --git a/src/tools/NullConsoleOutput.php b/src/tools/NullConsoleOutput.php index 875e961..d965fde 100644 --- a/src/tools/NullConsoleOutput.php +++ b/src/tools/NullConsoleOutput.php @@ -10,9 +10,9 @@ use Symfony\Component\Console\Output\ConsoleSectionOutput; use Symfony\Component\Console\Output\OutputInterface; -final class NullConsoleOutput implements ConsoleOutputInterface +final readonly class NullConsoleOutput implements ConsoleOutputInterface { - public function __construct(private readonly OutputInterface $output) + public function __construct(private OutputInterface $output) { } diff --git a/src/tools/SerializerJson.php b/src/tools/SerializerJson.php index bd82f5f..67960fb 100644 --- a/src/tools/SerializerJson.php +++ b/src/tools/SerializerJson.php @@ -9,9 +9,9 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; -final class SerializerJson +final readonly class SerializerJson { - private readonly Serializer $serializer; + private Serializer $serializer; public function __construct() { diff --git a/src/tools/TaskManagerOutput.php b/src/tools/TaskManagerOutput.php index 523a231..da7535e 100644 --- a/src/tools/TaskManagerOutput.php +++ b/src/tools/TaskManagerOutput.php @@ -10,9 +10,9 @@ use kuaukutsu\poc\task\event\EventSubscriberInterface; use kuaukutsu\poc\task\event\ProcessEvent; -final class TaskManagerOutput implements EventSubscriberInterface +final readonly class TaskManagerOutput implements EventSubscriberInterface { - public function __construct(private readonly ConsoleOutputInterface $output) + public function __construct(private ConsoleOutputInterface $output) { } diff --git a/tests/ProcessingExceptionTest.php b/tests/ProcessingExceptionTest.php new file mode 100644 index 0000000..5aedeb8 --- /dev/null +++ b/tests/ProcessingExceptionTest.php @@ -0,0 +1,133 @@ +taskQuery = self::get(TaskQuery::class); + $this->destroyer = self::get(TaskDestroyer::class); + $this->processing = self::get(TaskProcessing::class); + $this->builder = self::get(TaskBuilder::class); + + $this->options = new TaskManagerOptions( + bindir: __DIR__ . '/bin', + heartbeat: 5., + keeperInterval: 1., + ); + } + + /** + * @throws Exception + */ + public function testExceptionTaskProcess(): void + { + $this->processing->loadTaskProcess($this->options); + self::assertTrue($this->processing->hasTaskProcess()); + + $context = $this->processing->getTaskProcess(); + + $flag = new TaskFlag(); + $task = $this->taskQuery->getOne(new EntityUuid($context->task)); + self::assertEquals($flag->setRunning()->toValue(), $task->flag); + + $this->processing->next( + new TaskProcess( + $context->getHash(), + $context->task, + $context->stage, + $this->getProcess( + new TaskStateError( + new TaskStateMessage('error') + ) + ), + ) + ); + + self::assertFalse($this->processing->hasTaskProcess()); + + $task = $this->taskQuery->getOne(new EntityUuid($context->task)); + self::assertEquals($flag->setCanceled()->toValue(), $task->flag); + } + + protected function setUp(): void + { + $draft = $this->builder->create( + 'task test builder', + new EntityWrapper( + class: TestStageStub::class, + params: [ + 'name' => 'Test initialization.', + ], + ), + ); + + $this->task = $this->builder->build($draft); + } + + protected function tearDown(): void + { + $this->destroyer->purge( + new EntityUuid($this->task->getUuid()) + ); + } + + /** + * @throws Exception + */ + private function getProcess(TaskStateInterface $state): Process + { + $stub = $this->createMock(Process::class); + + $stub->method('isSuccessful') + ->willReturn(false); + + $stub->method('getOutput') + ->willReturn( + serialize($state) + ); + + return $stub; + } +}