Exemplo n.º 1
0
 public function perform()
 {
     // Make sure we catch and process fatal errors from within the job
     register_shutdown_function(function () {
         if (!($e = error_get_last()) || !in_array($e['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
             return;
         }
         $this->logger->error('Worker (fork): Job [ ' . $this->job->getId() . ' ] failed fatally with message: [ ' . $e['message'] . ' ]');
         $this->host->failJob($this->job, new \ErrorException($e['message'], $e['type'], 0, $e['file'], $e['line']));
     });
     try {
         $this->jobCreator->create($this->job)->perform();
     } catch (\Exception $e) {
         $this->logger->error('Worker (fork): Job [ ' . $this->job->getId() . ' ] failed with message: [ ' . $e->getMessage() . ' ]');
         $this->host->failJob($this->job, $e);
         throw $e;
     }
     $this->host->completeJob($this->job);
     $this->logger->debug('Worker (fork): Job [ ' . $this->job->getId() . ' ] completed successfully');
     return 0;
 }
Exemplo n.º 2
0
 /**
  * @param Job $job
  * @param Exception $error
  * @return $this
  */
 public function failJob(Job $job, Exception $error)
 {
     $this->complete($job->getId(), $error);
     return $this;
 }