Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running a task every five minutes without overlapping?

Quoting https://laravel.com/docs/5.1/scheduling#preventing-task-overlaps ,

$schedule->command('emails:send')->withoutOverlapping();

In this example, the emails:send Artisan command will be run every minute if it is not already running.

What if I wanted the task to run every five minutes instead? Could I do this?:

$schedule->command('emails:send')->everyFiveMinutes()->withoutOverlapping();
like image 596
neubert Avatar asked Dec 15 '25 00:12

neubert


1 Answers

Yes you can do this. command returns an instance of Event the underlying code for Event has a fluent interface which allows you to chain these together in this way.

You can see this for yourself if you look at the withoutOverlapping method.

/**
 * Do not allow the event to overlap each other.
 *
 * @return $this
 */
public function withoutOverlapping()
{
    $this->withoutOverlapping = true;
    return $this->skip(function () {
        return file_exists($this->mutexPath());
    });
}
like image 71
Mark Davidson Avatar answered Dec 16 '25 22:12

Mark Davidson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!