Monday, March 13, 2017

Is there a way to loop task scheduler?

I am using Laravel Task Scheduling and I scrape data from bunch of urls in a for loop. That's why I don't know for sure when one cycle finishes. I tried to setup a for loop in the Kernel's schedule() method as mentioned in this question but it doesn't seem to work efficiently.

protected function schedule(Schedule $schedule)
{
   $schedule->command('catalog:update')->everyMinute();
   sleep(5);
   $schedule->command('catalog:update')->everyMinute();
   sleep(5);
}

What I want to achieve is that detect when task is finished, and run it again accordingly. Like creating a never-ending loop, but they shouldn't overlap because it won't let the previous scraping finish I think (am I right?).

So I want something like:

protected function schedule(Schedule $schedule)
{
   $schedule->command('catalog:update');

   // Detect when completed {
   // run it again. Detect when completed again, etc as a loop. 
   //}

}



via senty

Advertisement