public function testRecreatedJobMatchesExistingJob() { $args = ['int' => 123, 'numArray' => [1, 2], 'assocArray' => ['key1' => 'value1', 'key2' => 'value2']]; Resque::enqueue('jobs', 'Test_Job', $args); $job = Job::reserve('jobs'); // Now recreate it $job->recreate(); $newJob = Job::reserve('jobs'); $this->assertEquals($job->payload['class'], $newJob->payload['class']); $this->assertEquals($job->payload['args'], $newJob->getArguments()); }
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 = Job::reserve('jobs'); $this->assertEquals(Status::STATUS_WAITING, $newJob->getStatus()); }
/** * Attempt to find a job from the top of one of the queues for this worker. * * @return Job|boolean Instance of Job if a job is found, false if not. */ public function reserve() { $queues = $this->queues(); if (!is_array($queues)) { return false; } foreach ($queues as $queue) { $this->log(array('message' => 'Checking ' . $queue, 'data' => array('type' => 'check', 'queue' => $queue)), self::LOG_TYPE_DEBUG); $job = 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; }
/** * Reserve and return the next available job in the specified queue. * * @param string $queue Queue to fetch next available job from. * @return Job Instance of Resque_Job to be processed, false if none or error. */ public static function reserve($queue) { return Job::reserve($queue); }