Example #1
0
 public function testShouldRun()
 {
     $date = new \DateTime('2015-01-02 03:04:05');
     $tests = ['* * * * *' => true, '4 * * * *' => true, '3 * * * *' => false, '*/2 * * * *' => true, '*/3 * * * *' => false, '2,3,4 * * * *' => true, '5,6,7 * * * *' => false, '2-4 * * * *' => true, '5-7 * * * *' => false, '4 3 2 1 5' => true, '* * * * 0' => false];
     foreach ($tests as $test => $result) {
         assert($result == DateUtils::shouldRun($test, $date), $test);
     }
 }
Example #2
0
 private function scheduleNew()
 {
     $lastCheck = $this->jobDao->getLastCheck();
     if ($lastCheck !== false && DateUtils::isSameMinute($this->now->format('Y-m-d H:i:s'), $lastCheck)) {
         return;
     }
     $this->jobDao->setLastCheck($this->now->format('Y-m-d H:i:s'));
     $this->logger->info('Schedule new tasks.');
     $jobs = $this->jobDao->findRunnable();
     foreach ($jobs as $job) {
         if (DateUtils::shouldRun($job['cron'], $this->now)) {
             $taskId = $this->createTask($job['id']);
             $this->tryRunTask($taskId);
         }
     }
 }