/** * Run the job. * * @return mixed Error from run; NULL if no error, a string message if there was an error. * @throw JQWorker_SignalException is the only exception that is re-thrown from here. * @see JQJob */ public function run(JQManagedJob $job) { if ($this !== $job) { throw new Exception("Must pass in the JQManagedJob, and yes, I know it's the same as the object used to call the run() method on. This is just a test to be sure you're paying attention."); } if (!$this->job instanceof JQJob) { throw new Exception("JQManagedJob.job is not a JQJob instance. Nothing to run."); } if ($this->isRunningLock) { throw new Exception("Local run lock already in use... can't run a job twice."); } $this->isRunningLock = true; // run the job $err = NULL; try { $disposition = ErrorManager::wrap(array($this->job, 'run'), array($this), array($this, 'errorHandlerFailJob')); switch ($disposition) { case self::STATUS_COMPLETED: $this->markJobComplete(); break; case self::STATUS_WAIT_ASYNC: $this->markJobWaitAsync(); break; default: throw new Exception("Invalid return value " . var_export($disposition, true) . " from job->run(). Return one of JQManagedJob::STATUS_COMPLETED, JQManagedJob::STATUS_WAIT_ASYNC, or JQManagedJob::STATUS_FAILED."); } } catch (JQWorker_SignalException $e) { // NOTE: a signal interrupts any line of code; from the try/catch above thru the cleanup code below // we throw here so that the same workflow can be used for errors in the try/catch and outsie of it // that way all signal handling during job execution is handled in one path, in the JQWorker. throw $e; } catch (Exception $e) { $err = $e->getMessage(); $this->markJobFailed($err); } return $err; }