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

Viewed 672

I have those 3 commands to run in schedule.

$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();

But in log, we can see only 2 of them are actually running.

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.

I can run that update:billing manually but it suddenly stopped to run in schedule.

All of them were running till yesterday.

Any help will be appreciated.

Edit:

update:sales also stopped now.

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
3 Answers

Check running processes, maybe the command is working (stuck) and do not run because of withoutOverlapping.

ps aux | grep 'php artisan'

I was having almost same issue few days back after some research I reached to the following solution,

    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
    }

Now only run your schedule command in cron job like schedule:run it will also prevent extra load on the server, I have found this answer on Laracast forget link else I would have shared!

I found a answer to that problem here. Hope it helps someone.

Just executed php artisan cache:clear on the project folder and all seems to be working now.

Related