public function perform()
{
Stats::decr('queued', 1);
Stats::decr('queued', 1, Queue::redisKey($this->queue, 'stats'));
if (Event::fire(Event::JOB_PERFORM, $this) === false) {
$this->cancel();
return false;
}
$this->run();
$retval = true;
try {
$instance = $this->getInstance();
ob_start();
if (method_exists($instance, 'setUp')) {
$instance->setUp();
}
call_user_func_array(array($instance, $this->method), array($this->data, $this));
if (method_exists($instance, 'tearDown')) {
$instance->tearDown();
}
$this->complete();
// setUp said don't perform this job
} catch (Exception\Cancel $e) {
$this->cancel();
$retval = false;
} catch (\Exception $e) {
$this->fail($e);
$retval = false;
}
$output = ob_get_contents();
while (ob_get_length()) {
ob_end_clean();
}
$this->redis->hset(self::redisKey($this), 'output', $output);
return $retval;
}
/** * Process a single job * * @param Job $job The job to be processed. */ public function perform(Job $job) { // Set timeout so as to stop any hanged jobs // and turn off displaying errors as it fills // up the console set_time_limit($this->timeout); ini_set('display_errors', 0); $job->perform(); switch ($job->getStatus()) { case Job::STATUS_COMPLETE: $this->log('Done job <pop>' . $job . '</pop> in <pop>' . $job->execTimeStr() . '</pop>', Logger::INFO); break; case Job::STATUS_CANCELLED: $this->log('Cancelled job <pop>' . $job . '</pop>', Logger::INFO); break; case Job::STATUS_FAILED: $this->log('Job ' . $job . ' failed: "' . $job->failError() . '" in ' . $job->execTimeStr(), Logger::ERROR); break; default: $this->log('Unknown job status "(' . gettype($job->getStatus()) . ')' . $job->getStatus() . '" for <pop>' . $job . '</pop>', Logger::WARNING); break; } }