示例#1
0
 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();
 }
示例#2
0
 /**
  * @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);
 }
示例#3
0
 /**
  * @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;
 }
示例#4
0
 public function buryJob($queueName, JobInterface $job)
 {
     $this->amqpStreamConnection->channel()->basic_nack($job->getData()['_delivery_tag']);
 }
示例#5
0
 public function serialize(JobInterface $job)
 {
     return new AMQPMessage(json_encode(['name' => $job->getName(), 'data' => $job->getData()]), ['delivery_mode' => 2]);
 }
示例#6
0
 public function buryJob($queueName, JobInterface $job)
 {
     $this->pheanstalk->bury(new Job($job->getData()['_beanstalk_id'], []));
 }
示例#7
0
 public function serialize(JobInterface $job)
 {
     return json_encode(['name' => $job->getName(), 'data' => $job->getData()]);
 }