Reputation: 1401
I was wondering if Laravel has a built in function to only run a scheduled task if the previous has finished.
I have a need to run a specific task every few seconds, but the task relies on querying another host that may at some point lose connection.
There are a couple of ways I thought about doing this, if there isn't:
Just hoping the task scheduler has something built in before I go down either of those routes ...
Upvotes: 2
Views: 2998
Reputation: 1401
Found the answer in the Docs :D
https://laravel.com/docs/5.3/scheduling
excerpt:
Preventing Task Overlaps
By default, scheduled tasks will be run even if the previous instance of the task is still running. To prevent this, you may use the withoutOverlapping method:
$schedule->command('emails:send')->withoutOverlapping();
In this example, the emails:send
Artisan command will be run every minute if it is not already running. The withoutOverlapping
method is especially useful if you have tasks that vary drastically in their execution time, preventing you from predicting exactly how long a given task will take.
Upvotes: 6