public function addJob(JobInterface $job, $routingKey = self::DEFAULT_ROUTING_KEY) { $model = \Task::getById($job->getId()); $model->broker_name = $this->name; $model->routing_key = $routingKey; return $model->save(); }
/** * @param JobInterface $job * * @return bool * * @throws \Exception */ public function execute(JobInterface $job) { $data = $job->getData(); if (!isset($data['callback'])) { throw new \InvalidArgumentException('Could not find callback.'); } if (!is_callable($data['callback'])) { throw new \InvalidArgumentException('The callback needs to be a callable.'); } $callback = $data['callback']; unset($data['callback']); return call_user_func($callback, $job->getName(), $data); }
/** * @return null|TaskInterface */ private function getNextTask() { pcntl_signal_dispatch(); if ($this->isTerminated) { return null; } if (null == $this->currentJob) { $this->currentJob = $this->getNextJob(); if (!$this->currentJob) { return null; } $this->jobs[$this->currentJob->getId()] = $this->currentJob; $this->currentJob->start(); } $task = $this->currentJob->getNextTask(); if (!$task) { $this->currentJob = $this->getNextJob(); if (!$this->currentJob) { return null; } $this->jobs[$this->currentJob->getId()] = $this->currentJob; $this->currentJob->start(); $task = $this->currentJob->getNextTask(); } return $task; }
public function buryJob($queueName, JobInterface $job) { $this->amqpStreamConnection->channel()->basic_nack($job->getData()['_delivery_tag']); }
public function serialize(JobInterface $job) { return new AMQPMessage(json_encode(['name' => $job->getName(), 'data' => $job->getData()]), ['delivery_mode' => 2]); }
public function buryJob($queueName, JobInterface $job) { $this->pheanstalk->bury(new Job($job->getData()['_beanstalk_id'], [])); }
public function serialize(JobInterface $job) { return json_encode(['name' => $job->getName(), 'data' => $job->getData()]); }