簡體   English   中英

Laravel 調度程序不運行命令,但可以手動運行

[英]Laravel Scheduler don't run commands, but they can be run manually

我有這 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
    }

現在只在像schedule:run這樣的 cron 作業中運行你的 schedule 命令,它還會防止服務器上的額外負載,我在 Laracast 上找到了這個答案忘記鏈接,否則我會分享!

我在這里找到了該問題的答案。 希望它可以幫助某人。

剛剛在項目文件夾上執行php artisan cache:clear ,現在似乎一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM