예제 #1
0
 public function resolveJobs()
 {
     if ($this->noNeedToRun()) {
         return;
     }
     $timeLimit = $this->configuration->timeout;
     $startTime = time();
     do {
         try {
             $job = $this->jobRepository->getActual();
             if (is_object($job)) {
                 $job->run();
             }
         } catch (Exception $e) {
             $record = new AuditRecord();
             $record->category = self::LogName;
             $record->message = (string) $e;
             $this->logger->log($record);
             if (!empty($job)) {
                 $job->status = Job::ErrorStatus;
                 $job->update();
             }
         }
         $timeToStop = !empty($timeLimit) ? time() >= $startTime + $timeLimit : true;
         if (!$timeToStop) {
             sleep(1);
         }
     } while (!$timeToStop);
     $this->jobRepository->cleanup($this->configuration->jobLifetime);
 }
 public function cleanUp()
 {
     $this->jobRepository->cleanup('5 minute');
     $latests = $this->jobRepository->getLatests(2);
     $this->assertTrue(is_array($latests));
     $this->assertEquals(1, sizeof($latests));
     $this->assertEquals(1, $latests[0]->id->getValue());
 }