Skip to main content

Delay Jobs if Some Condition Fails

Premium
3 min read

I want to show you how to delay job execution and retry jobs conditionally when working with Laravel queues.


Delay Start Of A Laravel Job

Sometimes you need to schedule a job to run in the future rather than immediately. For example, after a user registers, you might want to send a notification after some time.

When dispatching a job, you can chain a delay method which accepts a parameter - you can even use Carbon for more readable time expressions.

In this example, the job will be processed after 15 minutes, but in reality, it could take...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Daniela Venegas avatar

Would an early return work better here? does the job skips the rest of the code when encountring a $this->release()?

if (is_null($this->user->email_verified_at)) { $this->release(); }

// rest of the code

Nerijus avatar

In this case I think it would work, only thing you should need to add a return;. To check you could quickly try it