Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

withoutOverlapping() is not working in Laravel Schedule

$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
like image 413
Awais Mushtaq Avatar asked Jan 01 '16 10:01

Awais Mushtaq


People also ask

How do I schedule a job in Laravel?

The scheduler allows you to fluently and expressively define your command schedule within your Laravel application itself. When using the scheduler, only a single cron entry is needed on your server. Your task schedule is defined in the app/Console/Kernel.php file's schedule method.

What is WithoutOverlapping Laravel?

The WithoutOverlapping middleware provided by Laravel can be used to prevent overlapping of jobs based on an arbitrary key. For instance, in our case, it would be the user's id for which we are updating the wallet's balance.

What is cron job in Laravel 8?

Laravel Cron Job SchedulingLaravel's 'Command Scheduler' allows you to easily define the schedule of the commands within Laravel itself. When using the scheduler, only one Cron entry is needed on the server. Your task schedule is defined in the app/Console/Kernel. php file's schedule method.


1 Answers

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.

like image 79
jedrzej.kurylo Avatar answered Oct 04 '22 02:10

jedrzej.kurylo