reserve() public static method

Find the next available job from the specified queue and return an instance of Resque_Job for it.
public static reserve ( string $queue ) : false | object
$queue string The name of the queue to check for a job in.
return false | object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
Exemplo n.º 1
0
 public function testRecreatedJobMatchesExistingJob()
 {
     $args = array('int' => 123, 'numArray' => array(1, 2), 'assocArray' => array('key1' => 'value1', 'key2' => 'value2'));
     Resque::enqueue('jobs', 'Test_Job', $args);
     $job = Resque_Job::reserve('jobs');
     // Now recreate it
     $job->recreate();
     $newJob = Resque_Job::reserve('jobs');
     $this->assertEquals($job->payload['class'], $newJob->payload['class']);
     $this->assertEquals($job->payload['args'], $newJob->getArguments());
 }
Exemplo n.º 2
0
 public function testRecreatedJobWithTrackingStillTracksStatus()
 {
     $originalToken = Resque::enqueue('jobs', 'Test_Job', null, true);
     $job = $this->worker->reserve();
     // Mark this job as being worked on to ensure that the new status is still
     // waiting.
     $this->worker->workingOn($job);
     // Now recreate it
     $newToken = $job->recreate();
     // Make sure we've got a new job returned
     $this->assertNotEquals($originalToken, $newToken);
     // Now check the status of the new job
     $newJob = Resque_Job::reserve('jobs');
     $this->assertEquals(Resque_Job_Status::STATUS_WAITING, $newJob->getStatus());
 }
 /**
  * Reserve and return the next available job in the specified queue.
  *
  * @param string $queue Queue to fetch next available job from.
  * @return Resque_Job Instance of Resque_Job to be processed, false if none or error.
  */
 public static function reserve($queue)
 {
     require_once dirname(__FILE__) . '/Resque/Job.php';
     return Resque_Job::reserve($queue);
 }
Exemplo n.º 4
0
 /**
  * Reserve and return the next available job in the specified queue.
  *
  * @param string $queue Queue to fetch next available job from.
  * @return Resque_Job Instance of Resque_Job to be processed, false if none or error.
  */
 public static function reserve($queue)
 {
     return Resque_Job::reserve($queue);
 }
Exemplo n.º 5
0
 /**
  * Attempt to find a job from the top of one of the queues for this worker.
  *
  * @return object|boolean Instance of Resque_Job if a job is found, false if not.
  */
 public function reserve()
 {
     $queues = $this->queues();
     if (!is_array($queues)) {
         return;
     }
     foreach ($queues as $queue) {
         $this->log('Checking ' . $queue, self::LOG_VERBOSE);
         $job = Resque_Job::reserve($queue);
         if ($job) {
             $this->log('Found job on ' . $queue, self::LOG_VERBOSE);
             return $job;
         }
     }
     return false;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * Attempt to find a job from the top of one of the queues for this worker.
  *
  * @return object|boolean Instance of Resque_Job if a job is found, false if not.
  */
 public function reserve()
 {
     $queues = $this->queues();
     if (!is_array($queues)) {
         return;
     }
     foreach ($queues as $queue) {
         $this->log(array('message' => 'Checking ' . $queue, 'data' => array('type' => 'check', 'queue' => $queue)), self::LOG_TYPE_DEBUG);
         $job = Resque_Job::reserve($queue);
         if ($job) {
             $this->log(array('message' => 'Found job on ' . $queue, 'data' => array('type' => 'found', 'queue' => $queue)), self::LOG_TYPE_DEBUG);
             return $job;
         }
     }
     return false;
 }