Laravel “No scheduled commands are ready to run.”

后端 未结 13 1182
囚心锁ツ
囚心锁ツ 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:49

    I had the same problem. Every command was correctly registered but I always received the “No scheduled commands are ready to run.” message. The problem was that the website was in "maintenance mode" (php artisan down command) while we were doing updates and tests.

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

    Did you try running command manuallay?

    Run php artisan and see if your commands have registered.

    If you have registered your commands you should see command:daily-reset and command:monthly-reset under the list of available artisan commands.

    If you don't see them there go ahead and register your commands by adding it to commands property available in app/Console/Kernel.php.

    protected $commands = [
        'App\Console\Commands\YourFirstCommand',
        'App\Console\Commands\YourSecondCommand'
    ];
    

    Change crontab entry to

    * * * * * php /home/privates/public_html/staging/current/artisan schedule:run

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

    I think that my blog will help you answer your question. Please see the below or link: Laravel Crontab In many projects, you need use crontab (cron jobs) to execute some tasks as sending email or delete waste record in DB. With Laravel Project, you can do this easier.

    Create a command in Laravel 4:

    <?php
     
    use Illuminate\Console\Command;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Input\InputArgument;
     
    class FirstCommand extends Command {
     
            /**
             * The console command name.
             *
             * @var string
             */
            protected $name = 'user:active';
     
            /**
             * The console command description.
             *
             * @var string
             */
            protected $description = 'Command description.';
     
            /**
             * Create a new command instance.
             *
             * @return void
             */
            public function __construct()
            {
                    parent::__construct();
            }
     
            /**
             * Execute the console command.
             *
             * @return mixed
             */
            public function fire()
            {
                    echo "User Actived";
            }
            /**
             * Get the console command arguments.
             *
             * @return array
             */
            protected function getArguments()
            {
                    return array(
                    );
            }
     
            /**
             * Get the console command options.
             *
             * @return array
             */
            protected function getOptions()
            {
                    return array(
                            array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
                    );
            }
     
    }
    

    Next step, you need to register the command with Laravel CLI. So easy, you open app/start/artisan.php file, and add one line as below:

    Artisan::add(new FirstCommand);
    

    You are done creating Laravel Command. To test, you could use command below:

    $ php artisan user:active
    

    User Active The output above mean you successfully register a command.

    Finally, put your command into the crontab:

    crontab -e
    

    Add line (run command every 2 minutes):

    */2 * * * * php path_to_laravel_project/artisan user:active
    

    That’s all. Thank you for talking time to read this.

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

    To run the Cron Commands on the local server, follow these steps:

    1. I know you have already mentioned the command in app/console/Kernel.php
    2. Now open the command line, enter "crontab -e"
    3. Edit that file and mention the below code(without quote) to keep running PHP artisan schedule:run in the background

    "* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1"

    1. Enter "crontab -l" in the command line, it will list running crons

    Done !!

    Now, wait for cron to process your command. Cheers!!

    Reference- https://laravel.com/docs/7.x/scheduling#introduction

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

    For whatever reason cron does not recognize the named version of your task.

    So in your schedule instead of writing

    $schedule->command('command:task');

    you should use the path of the class, such as

    $schedule->command(\App\Console\Commands\TASK::class)

    ...the same goes for the scheduler on Laravel Forge!

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

    I realized that the problem for me was the below chained method:

    ->withoutOverlapping() 
    

    Once I removed that method, my commands started running and being found by the daemon process.

    I think there might be a bug with the method, but my project for now can take a bit overlapping so it's cool.

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