public function testJobWithTearDownCallbackFiresTearDown() { $payload = array('class' => JobWithTearDown::className(), 'args' => array('somevar', 'somevar2')); $job = new Job('jobs', $payload); $job->perform(); $this->assertTrue(JobWithTearDown::$called); }
/** * Tell Redis which job we're currently working on. * * @param object $job Job instance containing the job we're working on. */ public function workingOn(Job $job) { $job->worker = $this; $this->currentJob = $job; $job->updateStatus(Status::STATUS_RUNNING); $data = json_encode(array('queue' => $job->queue, 'run_at' => strftime('%a %b %d %H:%M:%S %Z %Y'), 'payload' => $job->payload)); Resque::redis()->set('worker:' . $job->worker, $data); }
public function testRecreatedJobWithTrackingStillTracksStatus() { $originalToken = Resque::enqueue('jobs', TestJob::className(), 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()); }
/** * 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 Job to be processed, false if none or error. */ public static function reserve($queue) { return Job::reserve($queue); }