*/ final class ReRunTask extends ScriptAction { public const OPTION_TASK = 'task'; public function run(): Report { /** @var TaskLogInterface $taskLog */ $taskLog = $this->getServiceLocator()->get(TaskLogInterface::SERVICE_ID); $filter = (new TaskLogFilter()) ->eq(TaskLogBrokerInterface::COLUMN_ID, $this->getOption(self::OPTION_TASK)); $collection = $taskLog->search($filter); if ($collection->isEmpty()) { return Report::createError('Task with corresponding id not found.'); } $entity = $collection->first(); $callback = $entity->getTaskName(); /** @var QueueDispatcherInterface $queueService */ $queueService = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); $created = $queueService->createTask(new $callback, $entity->getParameters(), $entity->getLabel()); return Report::createSuccess( sprintf('Original task `%s` was added to the queue under new id %s', $entity->getId(), $created->getId()) ); } protected function provideOptions(): array { return [ self::OPTION_TASK => [ 'prefix' => substr(self::OPTION_TASK, 0, 1), 'longPrefix' => self::OPTION_TASK, 'cast' => 'string', 'required' => true, 'description' => 'ID of the task, which should be run again' ] ]; } protected function provideDescription(): string { return 'Uses for restarting tasks from the task queue'; } }