예제 #1
0
 /**
  * @returns Job
  */
 public function getJob()
 {
     if ($this->isSleeping()) {
         return;
     }
     $hostId = $this->host->getId();
     foreach ($this->queues as $queue) {
         if ($job = $queue->nextJob($hostId)) {
             return Job::fromArray($job);
         }
     }
     $this->sleepFor(self::JOB_MISS_SLEEP_SECONDS);
 }
예제 #2
0
파일: Host.php 프로젝트: phresque/phresque
 /**
  * @param \DateTime $time
  * @return array
  */
 public function resolveScheduledJobs(\DateTime $time = null)
 {
     $jobs = $this->commandExecutor->execute(new ListRepeatedJobs());
     $jobIds = array();
     foreach ($jobs as $id => $job) {
         if (!$job['enabled']) {
             continue;
         }
         $cron = CronExpression::factory($job['cron']);
         $nextRun = $cron->getNextRunDate($time ?: '+ ' . self::CRON_TIME_SAFETY_MARGIN_SECONDS . ' seconds')->getTimestamp();
         $job['job']['id'] = $this->idGenerator->generate();
         $result = (new Queue($job['queue'], $this->commandExecutor, $this->idGenerator))->addTimedJob(Job::fromArray($job['job']), $nextRun, $job['lock'], $id);
         if ($result) {
             $jobIds[] = $job['job']['id'];
         }
     }
     return $jobIds;
 }