console = $name; } if (is_object($name)) { $this->task = $name; } $this->arguments = $arguments; } /** * 运行 cron 任务 * * @time 2020年07月04日 * @return void */ public function run() { if ($this->console) { Console::call($this->console, $this->arguments); } if ($this->task && method_exists($this->task, 'run')) { $this->task->run(); } } /** * 是否可运行 * * @time 2020年07月04日 * @return bool */ public function can() { if ($this->second) { $now = date('s', time()); return ($now % $this->second) == 0; } if ($this->expression) { $cron = CronExpression::factory($this->expression); return $cron->getNextRunDate(date('Y-m-d H:i:s'), 0 , true)->getTimestamp() == time(); } return false; } }