示例#1
0
 public static function cronHourly()
 {
     foreach (self::byType('weather') as $weather) {
         if ($weather->getIsEnable() == 1) {
             $cron = cron::byClassAndFunction('weather', 'pull', array('weather_id' => intval($weather->getId())));
             if (!is_object($cron)) {
                 $weather->reschedule();
             } else {
                 try {
                     $c = new Cron\CronExpression($cron->getSchedule(), new Cron\FieldFactory());
                     if (!$c->isDue()) {
                         $c->getNextRunDate();
                     }
                 } catch (Exception $ex) {
                     if ($c->getPreviousRunDate()->getTimestamp() < strtotime('now') - 300) {
                         $weather->reschedule();
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public function isDue()
 {
     $last = strtotime($this->getLastLaunch());
     $now = time();
     $now = $now - $now % 60;
     $last = $last - $last % 60;
     if ($now == $last) {
         return false;
     }
     if (is_array($this->getSchedule())) {
         foreach ($this->getSchedule() as $schedule) {
             try {
                 $c = new Cron\CronExpression($schedule, new Cron\FieldFactory());
                 try {
                     if ($c->isDue()) {
                         return true;
                     }
                 } catch (Exception $e) {
                 }
                 try {
                     $prev = $c->getPreviousRunDate()->getTimestamp();
                 } catch (Exception $e) {
                     return false;
                 }
                 $lastCheck = strtotime($this->getLastLaunch());
                 $diff = abs((strtotime('now') - $prev) / 60);
                 if ($lastCheck <= $prev && $diff <= config::byKey('maxCatchAllow') || config::byKey('maxCatchAllow') == -1) {
                     return true;
                 }
             } catch (Exception $e) {
             }
         }
     } else {
         try {
             $c = new Cron\CronExpression($this->getSchedule(), new Cron\FieldFactory());
             try {
                 if ($c->isDue()) {
                     return true;
                 }
             } catch (Exception $e) {
             }
             try {
                 $prev = $c->getPreviousRunDate()->getTimestamp();
             } catch (Exception $e) {
                 return false;
             }
             $lastCheck = strtotime($this->getLastLaunch());
             $diff = abs((strtotime('now') - $prev) / 60);
             if ($lastCheck <= $prev && $diff <= config::byKey('maxCatchAllow') || config::byKey('maxCatchAllow') == -1) {
                 return true;
             }
         } catch (Exception $exc) {
         }
     }
     return false;
 }
示例#3
0
 /**
  * Check if it's time to launch cron
  * @return boolean
  */
 public function isDue()
 {
     //check if already sent on that minute
     $last = strtotime($this->getLastRun());
     $now = time();
     $now = $now - $now % 60;
     $last = $last - $last % 60;
     if ($now == $last) {
         return false;
     }
     try {
         $c = new Cron\CronExpression($this->getSchedule(), new Cron\FieldFactory());
         try {
             if ($c->isDue()) {
                 return true;
             }
         } catch (Exception $e) {
         }
         try {
             $prev = $c->getPreviousRunDate()->getTimestamp();
         } catch (Exception $e) {
             return false;
         }
         $diff = abs((strtotime('now') - $prev) / 60);
         if (strtotime($this->getLastRun()) < $prev && ($diff <= config::byKey('maxCatchAllow') || config::byKey('maxCatchAllow') == -1)) {
             return true;
         }
     } catch (Exception $e) {
         log::add('cron', 'debug', 'Error on isDue : ' . $e->getMessage() . ', cron : ' . $this->getSchedule());
     }
     return false;
 }