Exemple #1
0
 /**
  * Pulls a single job from the queue (if none available, and if $timeout
  * specified, then wait only this much time for a job, otherwise throw a
  * `JobNotAvailableException`)
  *
  * @param int $timeout If specified, wait these many seconds
  * @return Job
  * @throws JobNotAvailableException
  */
 public function pull($timeout = 0)
 {
     $this->checkConnected();
     $jobs = $this->client->getJob($this->name, ['timeout' => $timeout, 'count' => 1]);
     if (empty($jobs)) {
         throw new JobNotAvailableException();
     }
     $jobData = $jobs[0];
     $job = $this->marshaler->unmarshal($jobData['body']);
     $job->setId($jobData['id']);
     return $job;
 }
Exemple #2
0
 /**
  * Pulls a single job from the queue (if none available, and if $timeout
  * specified, then wait only this much time for a job, otherwise return
  * `null`)
  *
  * @param int $timeout If specified, wait these many seconds
  * @return Job|null A job, or null if no job was found before timeout
  */
 public function pull($timeout = 0)
 {
     $this->checkConnected();
     $jobs = $this->client->getJob($this->name, ['timeout' => $timeout, 'count' => 1, 'withcounters' => true]);
     if (empty($jobs)) {
         return null;
     }
     $jobData = $jobs[0];
     $job = $this->marshaler->unmarshal($jobData[Response::KEY_BODY]);
     $job->setId($jobData[Response::KEY_ID]);
     $job->setNacks($jobData[Counters::KEY_NACKS]);
     $job->setAdditionalDeliveries($jobData[Counters::KEY_ADDITIONAL_DELIVERIES]);
     return $job;
 }