vendredi 1 septembre 2017

Laravel scheduled task without overlapping, run on demand

I have a scheduled task with Laravel defined as below to run every 10 minutes. I also need the same job to be run on-demand without it overlapping if it is already running or preventing the scheduled job starting to run if the on-demand job is running.

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
  $schedule->call(function () {
    $job = new \App\Jobs\ImportJob();
    $job->handle();
  })->name('Import')->everyTenMinutes()->withoutOverlapping();
}

Is there a nice, simple way of achieving this with the schedular API or should the Job take care of its own mutex flag?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire