修复定时任务无法准时启动

This commit is contained in:
JaguarJack
2020-07-08 17:48:45 +08:00
parent 4fec98f939
commit bcc4237140
4 changed files with 75 additions and 30 deletions

View File

@@ -106,17 +106,17 @@ class Cron
* @time 2020年07月04日
* @return bool
*/
protected function can()
public function can()
{
if ($this->second) {
$now = date('s', time());
return in_array($now, [--$now, $now, ++$now]);
return ($now % 5) == 0;
}
if ($this->expression) {
$cron = CronExpression::factory($this->expression);
return $cron->isDue('now');
return $cron->getNextRunDate(date('Y-m-d H:i:s'), 0 , true)->getTimestamp() == time();
}
return false;