Esempio n. 1
0
 public function loadJob(Job $job)
 {
     $jobData = $this->_table()->find()->where(['id' => $job->getId()])->hydrate(false)->first();
     if ($jobData === null) {
         throw new JobNotFoundException(sprintf('Job with id "%s" does not exist in the datastore.', $job->getId()));
     }
     return $job->setData($jobData);
 }
Esempio n. 2
0
 /**
  * @param \DelayedJobs\DelayedJob\Job $job Job to publish
  * @return void
  */
 public function publishJob(Job $job)
 {
     $delay = $job->getRunAt()->isFuture() ? Time::now()->diffInSeconds($job->getRunAt(), false) * 1000 : 0;
     //Invert the priority because Rabbit does things differently
     $jobPriority = $this->_manager->config('maximum.priority') - $job->getPriority();
     $jobData = ['priority' => $jobPriority > 0 ? $jobPriority : 0, 'delay' => $delay, 'payload' => ['id' => $job->getId()]];
     $this->getDriver()->publishJob($jobData);
 }
Esempio n. 3
0
 protected function _failedJob(Job $job, $exc)
 {
     if ($this->param('debug')) {
         throw $exc;
     }
     $this->out(sprintf('<error> - Execution failed</error> :: <info>%s</info>', $exc->getMessage()), 1, Shell::VERBOSE);
     $this->out($exc->getTraceAsString(), 1, Shell::VERBOSE);
     $this->djLog(__('Failed {0} because {1}', $job->getId(), $exc->getMessage()));
 }
Esempio n. 4
0
 /**
  * Checks if there already is a job with the same worker waiting
  *
  * @param \DelayedJobs\DelayedJob\Job $job Job to check
  * @return bool
  */
 public function isSimilarJob(Job $job)
 {
     $quoting = $this->connection()->driver()->autoQuoting();
     $this->connection()->driver()->autoQuoting(true);
     $conditions = ['worker' => $job->getWorker(), 'status IN' => [Job::STATUS_BUSY, Job::STATUS_NEW, Job::STATUS_FAILED, Job::STATUS_UNKNOWN]];
     if (!empty($job->getId())) {
         $conditions['id !='] = $job->getId();
     }
     $exists = $this->exists($conditions);
     $this->connection()->driver()->autoQuoting($quoting);
     return $exists;
 }
Esempio n. 5
0
 /**
  * @param \DelayedJobs\DelayedJob\Job $job Job being pushed to broker
  * @return bool|mixed
  */
 protected function _pushToBroker(Job $job)
 {
     if ($job->getId() === null) {
         throw new EnqueueException('Job has not been persisted.');
     }
     try {
         $event = $this->dispatchEvent('DelayedJobs.beforeJobQueue', [$job]);
         if ($event->isStopped()) {
             return $event->result;
         }
         $this->getMessageBroker()->publishJob($job);
         $this->dispatchEvent('DelayedJobs.afterJobQueue', [$job]);
         return true;
     } catch (\Exception $e) {
         Log::emergency(__('RabbitMQ server is down. Response was: {0} with exception {1}. Job #{2} has not been queued.', $e->getMessage(), get_class($e), $job->getId()));
         throw new EnqueueException('Could not push job to broker.');
     }
 }
Esempio n. 6
0
 public function afterExecute(Event $event, Job $job, $result, $duration)
 {
     $this->_lastJob = $job->getId();
     $this->_jobCount++;
     $this->out('');
     if ($result instanceof \Throwable) {
         $this->out(sprintf('<error> - Execution failed</error> :: <info>%s</info>', $result->getMessage()), 1, Shell::VERBOSE);
         $this->out($result->getTraceAsString(), 1, Shell::VERBOSE);
     } else {
         $this->out(sprintf('<success> - Execution successful</success> :: <info>%s</info>', $result), 1, Shell::VERBOSE);
     }
     $this->out(sprintf(' - Took: %.2f seconds', $duration / 1000), 1, Shell::VERBOSE);
     pcntl_signal_dispatch();
     $this->_timeLastJob = microtime(true);
     $this->_checkSuicideStatus();
 }