Laravel “No scheduled commands are ready to run.”

后端 未结 13 1181
囚心锁ツ
囚心锁ツ 2020-12-09 08:39

I\'ve set up the following Laravel commands:

protected function schedule(Schedule $schedule) {
        $schedule->command(\'command:daily-reset\')->dai         


        
相关标签:
13条回答
  • 2020-12-09 08:41

    When you run

    php artisan schedule:run
    

    in the server, where your project is stored, you could see all of your commands running with output, looking like this:

    "Running scheduled command: '/usr/local/bin/php' 'artisan' cache:update > '/dev/null' 2>&1 &"
    

    but only if the current time is the exact one, for which the command is scheduled. Otherwise you are going to see this output:

    "No scheduled commands are ready to run."
    

    For example, if you schedule the command for every five minutes and run the command in 09:07 o'clock you will see that there are no scheduled commands, but if you run it in 09:10 you will see your command running.

    In this way you can just schedule your command to run every 5 min just for debugging purposes:

    $schedule->command('command:daily-reset')->everyFiveMinutes();
    

    then observe if there is any error while running and eventually fix it. By me the problem was that I haven't installed GuzzleHttp (shame), so the fix was just running this in the terminal:

    composer require guzzlehttp/guzzle
    
    0 讨论(0)
  • 2020-12-09 08:41

    Since I still ran into this issue 4 years later (2019) and a different workaround worked for me, I think it is worth hinting the simple step that solved for me, which is: Use a shorter interval first.

    That seems to just wake it up to handle longer intervals in some ways. I had everyFiveMinutes() and for almost 2 hours it was getting the No scheduled commands are ready to run response. I simply changed it to everyMinute() and it started running correctly. I watched it consistently for like 10 minutes or so, then changed it back to everyFiveMinutes() and it all went smoothly.

    0 讨论(0)
  • 2020-12-09 08:45

    The full answer to this question is not listed above as far as I can see. Let's assume that our schedule is as follows:

    protected function schedule(Schedule $schedule)
    {
        $schedule
            -> command('cbh:dummyCommand')
            -> everyFiveMinutes()
            -> appendOutputTo ('/my/logs/laravel_output.log');
    }
    

    What I've discovered is that this code doesn't set your job to run every 5 minutes. Nor does it prevent the command running again if it was run less than 5-minutes ago.

    A better way to think about it is that this code sets the named command "to be runnable every time the minute-figure of the current time is 0 or 5". In other words, if I run the command-line argument: php artisan schedule:run at 11:04, then the response is:

    # No scheduled commands are ready to run.
    

    But if I run the same command at 11:00 or 11:05, then we get:

    # Running scheduled command: php artisan cbh:dummyCommand >> /my/logs/laravel_output.log 2>&1
    

    And I end up with output in my log-file.

    I discovered the above when my everyFiveMinutes() schedule was creating a log in my file every 10 minutes based on the fact that my task-scheduler was running every 2 minutes.

    However, this doesn't quite address your issue, given that the daily() schedule (0 0 * * *) aligns with your cron-job schedule. The only thing I can imagine is that there is some kind of misalignment with your time-zones as suggested by @Octavio Herrera. But that's difficult to say without knowing a bit more about your environment.

    0 讨论(0)
  • 2020-12-09 08:46

    The Laravel scheduled commands are based in the timezone that you have configured in your app/config/app.php file (laravel 5.1):

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */
    
    'timezone' => 'America/Bogota',
    

    So if you create a command and register it to run as a scheduled task with:

    $schedule->command('command:daily-reset')->daily();
    

    it will run every day at 00:00 OF THE TIMEZONE SPECIFIED (in this case America/Bogota)

    The same thing applies if you specify a time to run the task:

    $schedule->command('command:daily-reset')->daily()->at('02:30');
    

    This will run at 02:30 am in America/Bogota local time.

    0 讨论(0)
  • 2020-12-09 08:47

    NB: This is not answer for this question, but a clue for anyone debugging with php artisan schedule:run manually. Hope it saves someone a few minutes of headache.

    Check if the scheduled task can run immediately. You can use the exec method for that.

    <?php
    ...
    
    protected function schedule (Schedule $schedule) {
        $schedule -> exec("php artisan your:command");
    }
    

    The reason for this is that, you might be scheduling the task to run at a certain time and if that time isn't due yet, it will output: "No scheduled commands are ready to run."

    0 讨论(0)
  • 2020-12-09 08:47

    I've stuck with this problem No scheduled commands are ready to run. for an hours, but solve it easly:

    Problem was with rights to folder storage.

    So, i've set chmod -R 777 storage/* (i'm not sure is this is elegant way).

    After that cron starts working properly.

    0 讨论(0)
提交回复
热议问题