public function executeJob(Job $job) { $worker = $this->container->get($job->getName()); if (!$worker instanceof Worker) { throw new InvalidWorkerException("The worker {$job->getName()} is not an instance of " . Worker::class); } $worker->execute($job->getArguments()); }
/** * Called when a job failed * * @param Job $job * @param \Exception $exception */ protected function failedJob(Job $job, \Exception $exception) { if ($this->logger) { $context = ['name' => $job->getName(), 'arguments' => $job->getArguments(), 'message' => $exception->getMessage(), 'retryable' => !$exception instanceof UnrecoverableJobException]; if ($p = $exception->getPrevious()) { $context['cause'] = $p->getMessage(); } $this->logger->error('Job failed', $context); } $this->eventDispatcher && $this->eventDispatcher->dispatch(self::JOB_FAILED_EVENT, new FailedJobEvent($job, $exception)); }