/** * @param JobDefinition $job * * @throws \Exception */ public function runJob(JobDefinition $job) { $this->output->writeln(["\n", sprintf('<info>Running the %s job</info><comment>%s</comment>', $job->getName(), $job->getDescription() !== '' ? " > " . $job->getDescription() : '')]); foreach ($job->getTasks() as $task) { $preTaskEvent = new PreTaskEvent($job, $task); $this->dispatcher->dispatch(Event::PRE_TASK, $preTaskEvent); if ($preTaskEvent->isPropagationStopped()) { continue; } $service = $this->taskRegistry->findTaskByType($task->getType()); $this->prepareServiceForTask($service, $task); try { $service->run($this->output); } catch (TaskRuntimeException $e) { if (!$task->continueOnError()) { throw $e; } /** @var FormatterHelper $formatter */ $formatter = $this->helperSet->get('formatter'); $this->output->writeln(['', $formatter->formatBlock([sprintf('[Warning] Task: %s', $task->getType()), sprintf('%s', $e->getMessage())], 'bg=yellow;fg=black', true), '']); } } }