Exemple #1
0
 /**
  * @param JobList $jobList
  * @param ILogger $logger
  */
 public function execute($jobList, ILogger $logger = null)
 {
     $jobList->setLastRun($this);
     try {
         $this->run($this->argument);
     } catch (\Exception $e) {
         if ($logger) {
             $logger->error('Error while running background job: ' . $e->getMessage());
         }
     }
 }
Exemple #2
0
 /**
  * @param JobList $jobList
  * @param ILogger $logger
  */
 public function execute($jobList, ILogger $logger = null)
 {
     $jobList->setLastRun($this);
     try {
         $this->run($this->argument);
     } catch (\Exception $e) {
         if ($logger) {
             $logger->logException($e, ['app' => 'core', 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')']);
         }
     }
 }
 public function testSetLastRun()
 {
     $job = new TestJob();
     $this->instance->add($job);
     $jobs = $this->getAllSorted();
     $addedJob = $jobs[count($jobs) - 1];
     $timeStart = time();
     $this->instance->setLastRun($addedJob);
     $timeEnd = time();
     $addedJob = $this->instance->getById($addedJob->getId());
     $this->assertGreaterThanOrEqual($timeStart, $addedJob->getLastRun());
     $this->assertLessThanOrEqual($timeEnd, $addedJob->getLastRun());
 }