Published 8 months ago by deansatch
I have a few tasks that need to be constantly checked e.g. has account expired, is invoice due etc... and each task does something like 'find accounts that have past expiry date, loop through and send email to each user'
I have set these up in console/Kernel.php as:
$schedule->call('App\[email protected]')->everyMinute(); $schedule->call('App\[email protected]')->everyMinute();
If I run the command artisan schedule:run in terminal it works as expected. If I wait for another account to expire, type it again it runs.
Likewise if I set the command in supervisor I see it run and work as expected but then it exits and never runs again. I get an "Exited too quickly" error...sometimes it says FATAL, sometimes BACKOFF.
Supervisor conf file command:
command=php /var/www/mysite/artisan schedule:run
a) should I be using a different method? I see there are queues :work, :listen etc... but not really sure what the differences are between all these.
b) if I'm using correct method, how do I get it to run my schedules every minute?
supervisor will start a process, and keep it running. When you use supervisor it will warn you about "if the process fails within .... ms, it will not be restarted" ( the ... ms is a setting for supervisor)
So what happens is: Supervisor starts the scheduler, it has nothing to do so it exists immediately, and supervisor will no longer keep it running.
The scheduler is not ment to be kept running. You should run it in a cronjob set to run every minute.
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
more info: https://laravel.com/docs/5.5/scheduling
ps. The scheduler is a different part then the Queue system. The Queue worker should be kept running indefinitely (ie: by using the queue:work command) and should only be restarted when the code is updated.
@lostdreamer_nl Thanks for that - I can definitely sort the cron job out instead.
But would a queue worker be a more suitable option for what I am doing? It basically has to listen for certain events and/or membership accounts and when they hit a certain date/time, 'do something' e.g. send email(s). This can be at any minute of the day but might only happen 5 times a day, but could be 300. A cron would work but wondering if there is something more efficient that doesn't run queries every minute hoping for a result.
Laravel queues and schedules are two different things if you want to learn about queues here is the good article for you