Laravel / PHP PHP Free

Laravel: Dispatch a Delayed Queued Job with Retries

Send a queued job in Laravel after a delay, with retries and backoff, so slow work never blocks the request.

27 lines · Updated Nov 26, 2026

Preview of Laravel: Dispatch a Delayed Queued Job with Retries
laravel-delayed-queued-job.php
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendReportJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 3;                 // retry up to 3 times
    public $backoff = [60, 300];       // wait 1 min, then 5 min

    public function __construct(public int $userId) {}

    public function handle(): void
    {
        // Build and send the report here.
    }
}

// Dispatch it to run in 10 minutes:
// SendReportJob::dispatch($user->id)->delay(now()->addMinutes(10));

About this snippet

Some work should not happen right now: a reminder email one hour after signup, a follow-up message three days after purchase, cancelling an unpaid order after 30 minutes. This snippet dispatches a Laravel queued job with a delay and sensible retry settings, so delayed tasks run reliably in the background even if an external service fails temporarily.

How it works

  1. The job class implements ShouldQueue, so it runs on a queue worker instead of during the web request.
  2. It is dispatched with a delay, e.g. ->delay(now()->addHour()); the worker will not pick it up before that time.
  3. Properties such as $tries and $backoff control how many attempts are made and how long to wait between them.
  4. A failed() method can alert you when all attempts are used up.

How to use it

  • Set QUEUE_CONNECTION to database or redis — with sync, delays are ignored.
  • Run a worker permanently with Supervisor or systemd (see our VPS deployment guide).
  • Run php artisan queue:restart after every deploy so workers load the new code.

Write jobs safely

  • Re-check the situation when the job runs — maybe the order was paid in the meantime.
  • Make jobs idempotent: running twice should not send two emails or charge twice.
  • Pass IDs or models (which are serialised by ID), not large data.

Common problems

  • Job never runs: no worker is running, or the job is on a different queue name.
  • Delay too long on SQS: Amazon SQS supports a maximum delay of 15 minutes.

FAQ

Delayed job or scheduler? Use delayed jobs for "X time after an event", and the scheduler for fixed times like "every day at 9:00".

Related: Send WhatsApp messages · System design basics

How to install

Save the job as app/Jobs/SendReportJob.php and run php artisan queue:work (or a supervisor in production). Change $tries and $backoff to suit the job.

Share this snippet

See all
Chat with us