问题描述
我有3条命令可以按计划运行。
$schedule->command("update:branchsales")->everyFiveMinutes()->timezone('America/Sao_Paulo')->withoutOverlapping();
$schedule->command("update:billing")->everyFiveMinutes()->timezone('America/Sao_Paulo')->withoutOverlapping();
$schedule->command("update:sales")->everyFiveMinutes()->timezone('America/Sao_Paulo')->withoutOverlapping();
但是在日志中,我们只能看到其中有2个正在实际运行。
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:sales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:branchsales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:sales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:branchsales > '/dev/null' 2>&1
No scheduled commands are ready to run.
我可以手动运行update:billing
,但是突然停下来以按计划运行。
所有人都跑到昨天。
任何帮助将不胜感激。
编辑:
update:sales
现在也停止了。
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:sales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:branchsales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:sales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:branchsales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:branchsales > '/dev/null' 2>&1
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
Running scheduled command: '/usr/local/bin/php' 'artisan' update:branchsales > '/dev/null' 2>&1
解决方法
检查正在运行的进程,可能是由于withoutOverlapping
,命令正在运行(卡住)并且没有运行。
ps aux | grep 'php artisan'
,
几天后,我对以下解决方案进行研究后,我遇到了几乎相同的问题,
protected function osProcessIsRunning($needle)
{
// get process status. the "-ww"-option is important to get the full output!
exec('ps aux -ww',$process_status);
// search $needle in process status
$result = array_filter($process_status,function($var) use ($needle) {
return strpos($var,$needle);
});
// if the result is not empty,the needle exists in running processes
if (!empty($result)) {
return true;
}
return false;
}
protected function schedule(Schedule $schedule)
{
if (!$this->osProcessIsRunning('update:sales')) {
$schedule->command("update:branchsales")->everyFiveMinutes()->timezone('America/Sao_Paulo')->withoutOverlapping();
}
//Similarly do for other two commands
}
现在仅在cron作业中运行您的schedule命令,例如 schedule:run ,这还将防止服务器上的额外负载,我在Laracast上发现了这个答案,忘记了链接,否则我会共享!>
,我找到了here这个问题的答案。希望对别人有帮助。
只需在项目文件夹上执行php artisan cache:clear
,现在一切似乎都可以正常工作。