/** * Execute the next task on the queue * * @param string $queue * @param int $timeout * @throws \Exception * @throws \mcfedr\Queue\JobManagerBundle\Exception\UnrecoverableException * @throws \mcfedr\Queue\JobManagerBundle\Exception\ExecuteException */ public function execute($queue = null, $timeout = null) { $job = $this->manager->get($queue, $timeout); if (!$job) { return; } $task = json_decode($job->getData(), true); $this->logger->info('Got task', ['task' => $task['name'], 'options' => $task['options']]); try { /** @var Worker $worker */ $worker = $this->container->get($task['name']); foreach ($this->preListeners as $listener) { $listener->preTask($worker, $task['options']); } $worker->execute($task['options']); foreach ($this->postListeners as $listener) { $listener->postTask($worker, $task['options']); } $this->manager->delete($job); } catch (ServiceNotFoundException $e) { $this->manager->delete($job); $throw = new UnrecoverableException("Service for job not found", 0, $e); $throw->setJob($job); throw $throw; } catch (UnrecoverableException $e) { $this->manager->delete($job); $e->setJob($job); throw $e; } catch (\Exception $e) { throw new ExecuteException($job, $e); } }
/** * Remove a job * * @param $job * @throws WrongJobException * @throws NoSuchJobException */ public function delete(Job $job) { $this->manager->delete($job); }