withoutOverlapping() is not working in Laravel Schedule
12,514
Solution 1
Just name your task with a call to name() and chain the methods that define when your task should be run.
$schedule->call(function () {
//Some Code
})->everyFiveMinutes()
->name('some_name')
->withoutOverlapping();
For anonymous functions the name is required to prevent overlapping.
Solution 2
because these are different tasks, withoutOverlapping
works when there is a task scheduled everyFiveMinutes for example, and takes more than 5 minutes to finish so it will not start another instance of the same task until the old one is finished,
![Awais Mushtaq](https://lh4.googleusercontent.com/-hmmQeDx5aGc/AAAAAAAAAAI/AAAAAAAAAYs/B7UM8FxXRqk/photo.jpg?sz=256)
Author by
Awais Mushtaq
Updated on July 19, 2022Comments
-
Awais Mushtaq almost 2 years
$schedule->call(function () { error_log("Line Schedule 1:Start"); //Send Email error_log("Line Schedule 1:End"); })->everyFiveMinutes()->name('event_name:1')->withoutOverlapping(); $schedule->call(function () { error_log("Line Schedule 2:Start"); //Send Email error_log("Line Schedule 2:End"); })->everyFiveMinutes()->name('event_name:2')->withoutOverlapping(); $schedule->call(function () { error_log("Line Schedule 3:Start"); //Send Email error_log("Line Schedule 3:End"); })->everyFiveMinutes()->name('event_name:3')->withoutOverlapping();
i run these schulders using command php artisan schedule:run and i am running many instances in parallel. and my logs file says that schulder 2 is starting second time even its previous instance has not completed it yet .
[01-Jan-2016 11:30:08 UTC] Line Schedule 1:Start [01-Jan-2016 11:30:11 UTC] Line Schedule 2:Start [01-Jan-2016 11:30:13 UTC] Line Schedule 3:Start [01-Jan-2016 11:30:15 UTC] Line Schedule 1:End [01-Jan-2016 11:30:15 UTC] Line Schedule 2:Start [01-Jan-2016 11:30:17 UTC] Line Schedule 2:End [01-Jan-2016 11:30:17 UTC] Line Schedule 3:Start [01-Jan-2016 11:30:19 UTC] Line Schedule 3:End [01-Jan-2016 11:30:21 UTC] Line Schedule 2:End [01-Jan-2016 11:30:21 UTC] Line Schedule 3:Start [01-Jan-2016 11:30:22 UTC] Line Schedule 3:End [01-Jan-2016 11:30:25 UTC] Line Schedule 3:End
-
Ozan Kurt over 8 yearsWhat do you want to do with
withoutOverlapping
method? -
Awais Mushtaq over 8 yearsi am using 3 long time taking schedulers lets say S1,S2 and S3 and my server goes down because of these schedulers .i do not want to run any scheduler lets say S1 if previous one(S1) is not completed.
-
-
Awais Mushtaq over 8 years[01-Jan-2016 11:30:08 UTC] Line Schedule 1:Start [01-Jan-2016 11:30:11 UTC] Line Schedule 2:Start [01-Jan-2016 11:30:13 UTC] Line Schedule 3:Start [01-Jan-2016 11:30:15 UTC] Line Schedule 1:End [01-Jan-2016 11:30:15 UTC] Line Schedule 2:Start [01-Jan-2016 11:30:17 UTC] Line Schedule 2:End if you see my logs , Schedule 2 is staring second time even previously it is not completed yet.I do not see overlapping is working . i have logged in start and end of my each schedule .
-
Awais Mushtaq over 8 yearsi do not see overlapping working as my scheduler 2 is starting even its previous instance is not completed yet . i have commented log in above comment
-
jedrzej.kurylo over 8 yearsHow are you running them? By running "artisan schedule:run" twice in parallel?
-
Awais Mushtaq over 8 yearsyes i am testing on windows bu running command "php artisan schedule:run" in parallel. i am running many instances to test . actually my server goes down because of scheduling
-
jedrzej.kurylo over 8 yearsI just ran the above code, it works for me. When a task is running already, I'm getting "No scheduled commands are ready to run" when I run the second scheduler. Could you update the question with your current schedule? Please also run the scheduler twice and paste output you're getting from both calls
-
jedrzej.kurylo over 8 yearsAre you running multiple instances of "schedule:run" on the same server or different ones?
-
Awais Mushtaq over 8 yearsi am running them on same server . i hope you have understood my problem . which is running of schedule 2 second time even its previous instance has not done yet .
-
jedrzej.kurylo over 8 yearsOk, I've found the issue. When you run "schedule:run", first your Kernel's "schedule()" method is run to define the schedule and then, based on that schedule tasks are run. When you run first instance of "schedule:run", it schedules S1/S2/S3 to be run and then starts executing S1 task. When you run second instance of "schedule:run", it sees that S1 is being run, so it schedules S2/S3 to be run. When first instance finishes executing S1, it executes S2 because it's been scheduled to run, even though the second instance is already executing that. I'll submit a pull reuqest to Laravel to fix it.
-
Awais Mushtaq over 8 yearsand can you guide me how i can prevent my server from getting down ? i have some different logic in these 3 schedulers instead of sending email.all these tasks are quite time taking .
-
jedrzej.kurylo over 8 yearsI can't really tell what's causing servers to fail without seing the code and what's going on on the servers when you run it. If the operations are heavy it might just server that is too weak to handle them. Or overlapping tasks cause some kind of locks that, I can't really tell.
-
jedrzej.kurylo over 8 yearsThe pull request has been just merged to Laravel's 5.2 branch - github.com/laravel/framework/pull/11646