/** * Run a QueueWorker loop. * Runs a Queue Worker process which will try to find unassigned jobs in the queue * which it may run and try to fetch and execute them. * * @return void */ public function runOld() { // Enable Garbage Collector (PHP >= 5.3) if (function_exists('gc_enable')) { gc_enable(); } $exit = false; $starttime = time(); $group = null; if (isset($this->params['group']) && !empty($this->params['group'])) { $group = $this->params['group']; } while (!$exit) { $this->out('Looking for Job....'); $data = $this->CronTask->requestJob($this->_getTaskConf(), $group); if ($this->CronTask->exit === true) { $exit = true; } else { if ($data) { $this->out('Running Job of type "' . $data['jobtype'] . '"'); $taskname = 'queue_' . strtolower($data['jobtype']); $return = $this->{$taskname}->run(unserialize($data['data'])); if ($return == true) { $this->CronTask->markJobDone($data['id']); $this->out('Job Finished.'); } else { $failureMessage = null; if (isset($this->{$taskname}->failureMessage) && !empty($this->{$taskname}->failureMessage)) { $failureMessage = $this->{$taskname}->failureMessage; } $this->CronTask->markJobFailed($data['id'], $failureMessage); $this->out('Job did not finish, requeued.'); } } elseif (Configure::read('Queue.exitwhennothingtodo')) { $this->out('nothing to do, exiting.'); $exit = true; } else { $exit = true; } // check if we are over the maximum runtime and end processing if so. if (Configure::read('Queue.maxruntime') != 0 && time() - $starttime >= Configure::read('Queue.maxruntime')) { $exit = true; $this->out('Reached runtime of ' . (time() - $starttime) . ' Seconds (Max ' . Configure::read('Queue.maxruntime') . '), terminating.'); } if ($exit || rand(0, 100) > 100 - Configure::read('Queue.gcprob')) { $this->out('Performing Old job cleanup.'); $this->CronTask->cleanOldJobs(); } $this->hr(); } } }