private function isDue($class, $method, $when) { $next = Crontab::factory($when)->getNextRunDate()->getTimestamp(); $row = Raw::ScheduleTask()->where(['class', '=', $class])->where(['method', '=', $method])->first(true); if (!$row) { $row = Raw::ScheduleTask()->create(['class' => $class, 'method' => $method, 'next' => (int) $next])->save(); } else { if ($row->next <= time()) { $row->setNext($next)->save(); return true; } } return false; }
public function cron($expression = '* * * * *') { $next = Crontab::factory($expression)->getNextRunDate()->getTimestamp(); $key = sha1($this->task . $this->action . $expression); $file = '/home/php/storage/schedule/' . $key; if (file_exists($file)) { $aged = filemtime($file); if ($aged <= time()) { touch($file, $next); if (!$this->closure) { lib('utils')->backgroundTask('thin --task=' . $this->task . ' --action=' . $this->action); } else { if (is_callable($this->task)) { async($this->task); } else { lib('utils')->backgroundTask($this->task); } } } } else { $prev = Crontab::factory($expression)->getPreviousRunDate()->getTimestamp(); if ($prev <= time()) { touch($file, $next); if (!$this->closure) { lib('utils')->backgroundTask('thin --task=' . $this->task . ' --action=' . $this->action); } else { if (is_callable($this->task)) { async($this->task); } else { lib('utils')->backgroundTask($this->task); } } } } }