Run Laravel Schedule with delay

Viewed 1026

I have a lot of Laravel jobs that run everyMinute,

But I don't want all of them to run at the same time,

Is it possible to make some of them run everyMinute but with 1-2 seconds delay?

Something like this:

Job 1 > Every Minute at 00 seconds
Job 2 > Every minute at 05 seconds
Job 3 > Every minute at 10 seconds

For separate cron jobs I do it like: * * * * * ( sleep 30 ; /path/to/executable)

But I don't know how to do it with Laravel Schedules

2 Answers

As i see from your question, you probably need to take care of running a job in case of previous job events are returned or something like that.

And as you see, laravel jobs have the same timing accessible in server cron jobs as * * * * * meaning all days each one minutes.

So I've managed that with making custom Command:

php artisan make:command

And in my custom command, I checked if something happens, then my job runs...

You can also make a job in another job which depending on the parent job, it will execute or not.

I think that the easiest way to make it use php function sleep() in your Command on first line of handle() method.

Related