Laravel scheduled tasks being triggered multiple times

Viewed 1528

I have a cron job scheduled in laravel.

$schedule->command('my:command')->everyFiveMinutes();

It was running perfectly but after maintenance, cron job is being triggered multiple times occasionally. This behavior is not found at each run of the cron job.

This was being triggered once in every 5 minutes correctly. Due to our DB server maintenance, I had to put the website also on maintenance mode using php artisan down. Once the maintenance was over, I did php artisan up. Ever since then, occasionally(once a day or once in 2 days) cron job is being triggered like 5 or 6 times instead of once. Then in the next run, it gets back to normal (runs only once).

Laravel version 5.4 , php version of the server 7.0.

1 Answers

You have to know that Laravel tasks will not be triggered in maintenance mode (https://laravel.com/docs/5.8/scheduling#maintenance-mode).

Make sure that the task you are running takes less than five minutes to finish, if you have long-running tasks, then they might be triggered multiple times because of the allocated time for these tasks which is not sufficient.

Just keep it in mind that Laravel will not stop the tasks from being run, so it can't stop the task and run it again, this is the sysadmin duty to check if the task will be run within the given time frame.

Related