示例#1
0
 /**
  * @param Job $job
  * @return \Spork\Fork
  */
 protected function performJob(Job $job)
 {
     $this->host->disconnect();
     return $this->spork->fork(function () use($job) {
         $performer = new JobPerformer($this->host, $job, $this->jobCreator, $this->logger);
         return $performer->perform();
     });
 }
示例#2
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;
 }