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(); } } } } } }
<?php $crons = cron::all(); foreach ($crons as $cron) { $c = new Cron\CronExpression($cron->getSchedule(), new Cron\FieldFactory()); try { $c->getNextRunDate(); } catch (Exception $ex) { $cron->remove(); } }
public function calculateScheduleDate() { $calculatedDate = array('prevDate' => '', 'nextDate' => ''); if (is_array($this->getSchedule())) { $calculatedDate_tmp = array('prevDate' => '', 'nextDate' => ''); foreach ($this->getSchedule() as $schedule) { try { $c = new Cron\CronExpression($schedule, new Cron\FieldFactory()); $calculatedDate_tmp['prevDate'] = $c->getPreviousRunDate()->format('Y-m-d H:i:s'); $calculatedDate_tmp['nextDate'] = $c->getNextRunDate()->format('Y-m-d H:i:s'); } catch (Exception $exc) { //echo $exc->getTraceAsString(); } if ($calculatedDate['prevDate'] == '' || strtotime($calculatedDate['prevDate']) < strtotime($calculatedDate_tmp['prevDate'])) { $calculatedDate['prevDate'] = $calculatedDate_tmp['prevDate']; } if ($calculatedDate['nextDate'] == '' || strtotime($calculatedDate['nextDate']) > strtotime($calculatedDate_tmp['nextDate'])) { $calculatedDate['nextDate'] = $calculatedDate_tmp['nextDate']; } } } else { try { $c = new Cron\CronExpression($this->getSchedule(), new Cron\FieldFactory()); $calculatedDate['prevDate'] = $c->getPreviousRunDate()->format('Y-m-d H:i:s'); $calculatedDate['nextDate'] = $c->getNextRunDate()->format('Y-m-d H:i:s'); } catch (Exception $exc) { //echo $exc->getTraceAsString(); } } return $calculatedDate; }
public static function clean() { $crons = self::all(); foreach ($crons as $cron) { $c = new Cron\CronExpression($cron->getSchedule(), new Cron\FieldFactory()); try { if (!$c->isDue()) { $c->getNextRunDate(); } } catch (Exception $ex) { $cron->remove(); } } }