예제 #1
0
 /**
  * @param \DelayedJobs\DelayedJob\Job $job The job to fetch next sequence for
  * @return bool
  */
 public function fetchNextSequence(Job $job)
 {
     if ($job->getSequence() === null) {
         return false;
     }
     $next = $this->find()->select(['id', 'sequence', 'priority', 'run_at'])->where(['id !=' => $job->getId(), 'status' => Job::STATUS_NEW, 'sequence' => $job->getSequence()])->order(['priority' => 'ASC', 'id' => 'ASC'])->from([$this->table() . ' ' . $this->alias() . ' FORCE INDEX (status_2)'])->first();
     if (!$next) {
         $this->djLog(__('No more sequenced jobs found for {0}', $job->getSequence()));
         return false;
     }
     $job = new Job($next->toArray());
     return $job;
 }
예제 #2
0
 /**
  * @param \DelayedJobs\DelayedJob\Job $job Job that has been completed
  * @param string|null|\Cake\I18n\Time $result Message to store with job
  * @param int $duration How long execution took
  * @return \DelayedJobs\DelayedJob\Job|bool
  */
 public function completed(Job $job, $result = null, $duration = 0)
 {
     $job->setStatus(Job::STATUS_SUCCESS)->setEndTime(Time::now())->setDuration($duration)->addHistory($result);
     if ($job->getSequence() !== null) {
         $this->enqueueNextSequence($job);
     } else {
         $this->_persistToDatastore($job);
     }
     $event = $this->dispatchEvent('DelayedJob.jobCompleted', [$job, $result]);
     $this->_enqueueFollowup($job, $event->result ? $event->result : $result);
     return $job;
 }