From fa4246d7d455c799501e9e559c49635f00cd0078 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Thu, 3 Nov 2022 10:35:20 +0100 Subject: [PATCH] TASK: Remove async functionality --- Classes/Command/AbstractScheduledCommand.php | 40 --------- .../ExecuteScheduledCommandsCommand.php | 42 ---------- ...cuteScheduledCommandsCommandController.php | 43 ---------- Classes/Command/ScheduledCommandInterface.php | 24 ------ Classes/Integration/Clock.php | 28 ------- Classes/Integration/ClockInterface.php | 22 ----- Classes/Middleware/SchedulerMiddleware.php | 60 ------------- Classes/Scheduler/Scheduler.php | 84 ------------------- Classes/Scheduler/SchedulerInterface.php | 27 ------ Classes/Scheduler/Task/CommandTask.php | 46 ---------- Configuration/Services.php | 2 - ext_localconf.php | 11 --- 12 files changed, 429 deletions(-) delete mode 100644 Classes/Command/AbstractScheduledCommand.php delete mode 100644 Classes/Command/ExecuteScheduledCommandsCommand.php delete mode 100644 Classes/Command/ExecuteScheduledCommandsCommandController.php delete mode 100644 Classes/Command/ScheduledCommandInterface.php delete mode 100644 Classes/Integration/Clock.php delete mode 100644 Classes/Integration/ClockInterface.php delete mode 100644 Classes/Middleware/SchedulerMiddleware.php delete mode 100644 Classes/Scheduler/Scheduler.php delete mode 100644 Classes/Scheduler/SchedulerInterface.php delete mode 100644 Classes/Scheduler/Task/CommandTask.php delete mode 100644 ext_localconf.php diff --git a/Classes/Command/AbstractScheduledCommand.php b/Classes/Command/AbstractScheduledCommand.php deleted file mode 100644 index 4273766..0000000 --- a/Classes/Command/AbstractScheduledCommand.php +++ /dev/null @@ -1,40 +0,0 @@ -timestamp = $timestamp; - } - - public function getTimestamp(): int - { - return $this->timestamp; - } -} diff --git a/Classes/Command/ExecuteScheduledCommandsCommand.php b/Classes/Command/ExecuteScheduledCommandsCommand.php deleted file mode 100644 index 29a280e..0000000 --- a/Classes/Command/ExecuteScheduledCommandsCommand.php +++ /dev/null @@ -1,42 +0,0 @@ -commandBus = $commandBus; - } - - public function getCommandBus(): CommandBusInterface - { - return $this->commandBus; - } -} diff --git a/Classes/Command/ExecuteScheduledCommandsCommandController.php b/Classes/Command/ExecuteScheduledCommandsCommandController.php deleted file mode 100644 index cd507ee..0000000 --- a/Classes/Command/ExecuteScheduledCommandsCommandController.php +++ /dev/null @@ -1,43 +0,0 @@ -commandBus = $commandBusFactory->create(); - } - - public function executeScheduledCommandsCommand() - { - $executeScheduledCommandsCommand = new ExecuteScheduledCommandsCommand($this->commandBus); - $this->commandBus->handle($executeScheduledCommandsCommand); - } -} diff --git a/Classes/Command/ScheduledCommandInterface.php b/Classes/Command/ScheduledCommandInterface.php deleted file mode 100644 index 1a572a7..0000000 --- a/Classes/Command/ScheduledCommandInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -scheduler = $scheduler; - $this->clock = $clock; - } - - public function execute($command, callable $next) - { - if (($command instanceof ScheduledCommandInterface) && ($command->getTimestamp() > $this->clock->getCurrentTimestamp())) { - return $this->scheduler->schedule($command); - } - - if ($command instanceof ExecuteScheduledCommandsCommand) { - $commands = $this->scheduler->getCommands(); - foreach ($commands as $scheduledCommand) { - $command->getCommandBus()->handle($scheduledCommand); - // Only remove command if no exception occurred - $this->scheduler->removeCommand($scheduledCommand); - } - } else { - return $next($command); - } - } -} diff --git a/Classes/Scheduler/Scheduler.php b/Classes/Scheduler/Scheduler.php deleted file mode 100644 index 3f5d6ef..0000000 --- a/Classes/Scheduler/Scheduler.php +++ /dev/null @@ -1,84 +0,0 @@ -scheduler = $scheduler; - $this->clock = $clock; - } - - public function schedule(ScheduledCommandInterface $command, int $id = null): string - { - /** @var CommandTask $task */ - $task = new CommandTask($command); - $task->setTaskGroup(0); - $execution = GeneralUtility::makeInstance(Execution::class); - $execution->setStart($command->getTimestamp()); - $task->setExecution($execution); - $task->setDisabled(1); - $task->setDescription(self::TASK_DESCRIPTION_IDENTIFIER); - $this->scheduler->addTask($task); - - return (string)$task->getTaskUid(); - } - - public function getCommands(): array - { - return array_map(static function (CommandTask $commandTask) { - return $commandTask->getCommand(); - }, $this->fetchCommandTasks()); - } - - private function fetchCommandTasks(): array - { - return $this->scheduler->fetchTasksWithCondition(sprintf('nextexecution <= %d AND description = "%s"', $this->clock->getCurrentTimestamp(), self::TASK_DESCRIPTION_IDENTIFIER), true); - } - - public function removeCommand(ScheduledCommandInterface $command) - { - /** @var CommandTask[] $tasks */ - $tasks = $this->fetchCommandTasks(); - - foreach ($tasks as $task) { - if ($command === $task->getCommand()) { - $this->scheduler->removeTask($task); - } - } - } -} diff --git a/Classes/Scheduler/SchedulerInterface.php b/Classes/Scheduler/SchedulerInterface.php deleted file mode 100644 index 1b26b40..0000000 --- a/Classes/Scheduler/SchedulerInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -command = $command; - parent::__construct(); - } - - public function getCommand(): ScheduledCommandInterface - { - return $this->command; - } - - public function execute() - { - } -} diff --git a/Configuration/Services.php b/Configuration/Services.php index 954e57a..35d199e 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -11,9 +11,7 @@ ->autoconfigure(); $services->load('Ssch\\T3Tactician\\', __DIR__ . '/../Classes/')->exclude([ - __DIR__ . '/../Classes/Command/ExecuteScheduledCommandsCommand.php', __DIR__ . '/../Classes/Middleware/InvalidCommandException.php', - __DIR__ . '/../Classes/Scheduler/Task', __DIR__ . '/../Classes/Validator/NoValidatorFoundException.php', __DIR__ . '/../Classes/CommandAlreadyAssignedToHandlerException.php', ]); diff --git a/ext_localconf.php b/ext_localconf.php deleted file mode 100644 index 995d446..0000000 --- a/ext_localconf.php +++ /dev/null @@ -1,11 +0,0 @@ - 't3_tactician', - 'title' => 'Execute command task', - 'description' => 'Execute command task', -]; - -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = \Ssch\T3Tactician\Command\ExecuteScheduledCommandsCommandController::class;