2

I am trying to configure laravel task schedular , I am priting numbers from 0 to infinity to just test why withoutoverlapping() isn't working.

My code :

protected function schedule(Schedule $schedule)
{
    $schedule->call(function (Request $request) 
    {
         $i=0;

         while(1)
         {
               echo $i."-";
               sleep(3);
               $i++;
         }
    })->everyMinute()->name('mailfetch')->withoutOverlapping();
}

If my schedular is running and I am trying to run another schedular then that should not execute, but in my case both schedulars start running and start priting data.

Output:

enter image description here

Everything seems to be correct but dont' know why is that happening.

Vishal Shetty
  • 1,618
  • 1
  • 27
  • 40
  • Just try to delete `->everyMinute()` and test, it will still run evry minute to test that make just count to three to see if it will rerun again !! – Maraboc Jul 12 '17 at 12:00
  • I deleted `->everyMinute()` but still it is running even if previous task is alreading running – Vishal Shetty Jul 12 '17 at 12:04

1 Answers1

0

It will not overlap only if you launch them in the same minute. Because, you said to your process: "start an infinite loop every minute". So when you run your new instance, maybe you are in a new minute.

If you want to try something about overlapping, you could try:

$schedule->call(function (Request $request) {
    echo 'start';
    sleep(120);
    echo '- end';
})->dailyAt('13:00')->withoutOverlapping();
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
  • but i see laravel documentation (https://laravel.com/docs/5.4/scheduling#preventing-task-overlaps) , it says that to prevent execution of another task if already there is running one – Vishal Shetty Jul 12 '17 at 12:06
  • But only if it's running the same one. – rap-2-h Jul 12 '17 at 12:09
  • see I executed same task twice in same minute , but still both of them are printing the values at same time, check this http://prntscr.com/fuqrkm – Vishal Shetty Jul 12 '17 at 12:12