reserveBlocking() public static method

Find the next available job from the specified queues using blocking list pop and return an instance of Resque_Job for it.
public static reserveBlocking ( array $queues, integer $timeout = null ) : false | object
$queues array
$timeout integer
return false | object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
Ejemplo n.º 1
0
 /**
  * @param  bool            $blocking
  * @param  int             $timeout
  * @return object|boolean               Instance of Resque_Job if a job is found, false if not.
  */
 public function reserve($blocking = false, $timeout = null)
 {
     $queues = $this->queues();
     if (!is_array($queues)) {
         return;
     }
     if ($blocking === true) {
         $job = Resque_Job::reserveBlocking($queues, $timeout);
         if ($job) {
             $this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
             return $job;
         }
     } else {
         foreach ($queues as $queue) {
             $this->logger->log(Psr\Log\LogLevel::INFO, 'Checking {queue} for jobs', array('queue' => $queue));
             $job = Resque_Job::reserve($queue);
             if ($job) {
                 $this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
                 return $job;
             }
         }
     }
     return false;
 }