/** * Check if there are any upcoming schedules */ public static function check() { $numAdded = 0; foreach (self::getList() as $sheduleItem) { $storedLastRunTime = strtotime($sheduleItem->lastRun == '' ? $sheduleItem->start : $sheduleItem->lastRun); $previousCalculatedRunTime = CronParser::lastRun($sheduleItem->cron); // This looks at when the item had run. If the stored value is less than // the calculated value means that we have past a run period. So need to run if ($storedLastRunTime < $previousCalculatedRunTime) { // Update the run time to now $sheduleItem->lastRun = strftime('%Y-%m-%d %H:%M', $previousCalculatedRunTime); $sheduleItem->save(); // Enqueue a new item to run $job = new Cron(['ref' => $sheduleItem->id, 'cmd' => $sheduleItem->cmd]); $job->save(); $numAdded++; } } return $numAdded; }
public static function add($command, $id = 0, $priority = 0) { $cronJob = new Cron(['command' => $command, 'ref' => $id, 'status' => self::STATUS_NEW, 'priority' => $priority]); $cronJob->save(); return $cronJob; }