【问题标题】:Laravel Scheduler don't run commands, but they can be run manuallyLaravel Scheduler 不运行命令,但可以手动运行
【发布时间】:2020-08-13 11:03:14
【问题描述】:

我有这 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

【问题讨论】:

    标签: php laravel schedule


    【解决方案1】:

    检查正在运行的进程,可能命令正在运行(卡住)并且由于withoutOverlapping 而没有运行。

    ps aux | grep 'php artisan'
    

    【讨论】:

    • 仅更新:branchsales 正在运行,还有其他猜测吗?
    • 我删除 withoutOverlapping 只是为了测试,它有效!我只是不知道,为什么它昨天工作,而今天没有,有什么更新?
    • @ThRnk idk 为什么会出现重叠问题。添加日志以启动/完成控制台命令。或者添加一些监视器包,例如 github.com/spatie/laravel-schedule-monitor
    【解决方案2】:

    经过一些研究,几天前我遇到了几乎相同的问题,我找到了以下解决方案,

        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
        }
    

    现在只在像 schedule:run 这样的 cron 作业中运行你的调度命令,它还可以防止服务器上的额外负载,我在 Laracast 上找到了这个答案忘记链接,否则我会分享!

    【讨论】:

    • 我删除 withoutOverlapping 只是为了测试,它有效!我只是不知道,为什么它昨天工作,而今天没有,有什么更新?
    • 据我所知,如果我们在服务器上手动运行命令,它会运行一段时间,然后在一段时间后停止,所以我所做的是编写这个函数并在每次运行后继续运行分钟,所以如果它停止了,它会重新启动我们的命令,经过很多方法,这对我有用。
    【解决方案3】:

    我找到了该问题的答案here。希望它可以帮助某人。

    刚刚在项目文件夹上执行了php artisan cache:clear,现在似乎一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-01
      • 1970-01-01
      • 2021-09-23
      • 2019-11-05
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多