'No scheduled commands are ready to run | only in $schedule

  • Laravel Version: 5.7.25
  • PHP Version: 7.2.14
  • Database Driver & Version: MySQL 2ª gen. 5.7

Hi, Sorry for the trouble, I have this problem in creating a scheduled command.

Description:

In our crontab -e user we have inserted the following on Debian:

* * * * * cd /var/www/myfolder.com/ && php artisan schedule:run >> crontab.laravel

We have correctly entered the schedule function as follows:

app/console/kernel.php

  <?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;


class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
//        'App\Console\Commands\HelpCenter',
        Commands\HelpCenter::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('elena:help')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }

}

but the result continues to be No scheduled commands are ready to run we tried all the combinations impossible but nothing. If we uncomment the function Artisan call working, the script is executed

Try to force command crontab -e

To better understand where the problem lies We have added a crontab directly with the command without going through the schedule as :

* * * * * cd /var/www/myfolder.com/ && php artisan elena:help >> crontab.laravel

This command runs perfectly every minute so we can not figure out where the problem is. if you have the patience to give us some advice we will be happy. good day



Solution 1:[1]

I copy this here because this solved my issue. It's @piscator comment above.

"Did you run php artisan cache:clear? There might be a schedule file cached in your storage/framework folder."

EDIT:

This issue was giving me a lot of trouble. I'm using Laravel 5.8 and I couldn't make it work with ->withoutOverlapping(); The task will die after a while without apparent reasons and then the cron job couldn't start it again because ->withoutOverlapping() was preventing it.

Finally I found a solution here:

Basically, instead of using Laravel's ->withoutOverlapping(), you check yourself if the task is already running.

// start the queue worker, if its not running
$command = "queue:work --queue=high,email,default,low --tries=3 --delay=3";
if (!$this->osProcessIsRunning($command)) {
    $schedule->command($command)->everyMinute()
                                ->runInBackground()
                                ->appendOutputTo(storage_path('logs/queue.log'));
}

// function for checking if the task is running
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;
}

Thanks to @henryonsoftware for the solution

Solution 2:[2]

I don't know if I am late, but I have a solution for you. JUST ADD THE TIMEZONE IN THE SCHEDULE METHOD. it will start working well.

Example:

$schedule->command('tenam:before')
        ->dailyAt('22:28')->timezone('Asia/Kolkata');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2