예제 #1
0
 /**
  * @inheritdoc
  */
 public function reserveJob($queues = null, $blocking = true, $timeout = 0)
 {
     if ($queues) {
         $queues = array_map(function ($queue) {
             return $this->getQueueKeyPrefix() . $queue;
         }, $queues);
     } else {
         $queues = $this->getQueueKeyNames();
     }
     if ($blocking) {
         $output = $this->client->blpop($queues, $timeout);
         if (!$output) {
             return null;
         }
         list($key, $json) = $output;
         $job = JobReflector::fromJSON($json);
         JobReflector::setQueue($job, $this->getQueueForKey($key));
         return $job;
     } else {
         foreach ($queues as $key) {
             $json = $this->client->lpop($queues);
             if ($json) {
                 $job = JobReflector::fromJSON($json);
                 JobReflector::setQueue($job, $this->getQueueForKey($key));
                 return $job;
             }
         }
         return null;
     }
 }