laravel cannot run scheduled command, while queue:listen run schedule() periodically

后端 未结 2 1216
故里飘歌
故里飘歌 2020-12-20 09:43

Note: My question has nothing to do with Command schedule in Laravel which schedule not work. But in my question the scheduling works, but it cannot call the art

相关标签:
2条回答
  • 2020-12-20 10:01

    It costs me a day to google the issue, read laravel docs, and run many test. Finally I make it out.

    Laravel's artisan queue:listen command call the schedule() in the Kernel.php periodically, while it only run the Log::info() in the schedule() not the $schedule->command()(Here I'm also confused).

    I've four queue running, for queue1 sudo -u www-data php artisan queue:work --queue=queue1 --env=worker_env --delay=3 --timeout=600. Same with queue2, 3, 4. So the Log::info() in the schedule() will executed four times every 3 seconds.

    Above make me thought the schedule works well. Actually, the schedule is not executed. I found /etc/cron.minutely/printer-task-minute have no x privilege, so I add the x privilege for it. And I found I didn't config the crontab file, so I add * * * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.minutely ) to /etc/crontab(I'm not familar with cron).

    Solution:
      Config the cron like above, or refer to the manual.
      Change queue:listen to queue:work(When changed to queue:work, schedule() will not executed by queue periodically, I also don't know the reason here.).

    0 讨论(0)
  • 2020-12-20 10:09

    I think you should be using the below command

    $schedule->command('printer_serving')->everyMinute()‌​;
    
    0 讨论(0)
提交回复
热议问题