Skip to content

Expert Answers to Your Magento, Shopify & Shopware Questions

Vendor-neutral, engineer-written explanations. Clear definitions first, then practical steps with real examples — no fluff.

Stagebit builds and maintains stores on Magento, Adobe Commerce, Shopify, Shopware, and Laravel, and this library holds the questions our own engineers get asked most often on each platform.

How do I handle Laravel jobs that fail repeatedly?

SB
Written by Stagebit Engineering Team
Updated December 2026 6 min read Verified by engineers

A job that keeps failing is usually hitting an error that more retries cannot fix. To handle Laravel jobs that fail repeatedly, cap the attempts and space them out. Stop retrying errors that will never succeed. Let the final failure land in your failed-job storage, where you can read the exception, fix the cause, and replay the job. The Laravel controls below come from Laravel’s queue documentation.

Quick answer

Retry temporary failures a limited number of times and fail permanent ones at once. For temporary errors, set #[Tries(5)] and #[Backoff([10, 30, 60])]. For permanent errors, use dontRetry or $this->fail(). To quietly discard a job whose Eloquent model no longer exists, use #[DeleteWhenMissingModels]. Add a failed() method for alerts. Then check php artisan queue:failed, find the cause, fix it, and replay it with queue:retry and the job’s ID. Never use --tries=0 as a fix, because it retries a job forever.

Why do Laravel jobs fail repeatedly?

Each retry replays the same payload against the same code. Retrying only helps when the cause is temporary.

  • A temporary cause, like an API timeout or a database deadlock, often succeeds on a later attempt.
  • A permanent cause, such as a bug or an invalid payload, fails on every attempt.
  • A timeout longer than the connection’s retry_after value lets a second worker take the job and run it twice.

A job can also run out of attempts without handle() ever finishing successfully. Laravel attempts a job only once unless you set a higher limit. Each of these uses up an attempt:

  • An unhandled exception, which releases the job back onto the queue.
  • A manual release() call from inside the job.
  • A release by middleware such as RateLimited or WithoutOverlapping.
  • A timeout, which also uses one attempt.

How do you handle Laravel jobs that fail repeatedly?

Diagram of Laravel jobs that fail repeatedly: attempts, wait before retry, failed-job storage, then queue:retry after the fix

The examples use Laravel 13 attributes. On Laravel 12 and earlier, set the same values as class properties such as $tries and $timeout.

1. Cap attempts and space them out

Set the maximum with #[Tries(5)] on the job or --tries=3 on queue:work. The job-level value wins over the command line. Add #[Backoff([10, 30, 60])] to wait 10, 30, then 60 seconds between attempts. Spacing retries gives a struggling third-party API time to recover.

<?php

namespace App\Jobs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\Timeout;
use Illuminate\Queue\Attributes\Tries;
use Throwable;

#[Tries(5)]
#[Backoff([10, 30, 60])]
#[Timeout(30)]
class SyncOrderToErp implements ShouldQueue
{
    use Queueable;

    public function __construct(public int $orderId)
    {
    }

    public function handle(): void
    {
        // Send the order to the ERP API
    }

    public function failed(?Throwable $exception): void
    {
        logger()->error('Order sync failed', [
            'order_id' => $this->orderId,
            'error' => $exception?->getMessage(),
        ]);

        // Notify the team or flag the order for manual review
    }
}

2. Stop retrying errors that cannot succeed

Retrying an invalid payload only wastes workers. Call $this->fail($exception) inside handle() to mark one job failed immediately.

To stop retries for an exception type application-wide, register it with dontRetry in the withExceptions closure in bootstrap/app.php. Use dontRetryWhen if the decision depends on the exception’s details.

use App\Exceptions\InvalidOrderException;
use Illuminate\Foundation\Configuration\Exceptions;

->withExceptions(function (Exceptions $exceptions): void {
    $exceptions->dontRetry([
        InvalidOrderException::class,
    ]);
})

To fail one job on specific exceptions while still retrying the rest, return FailOnException from the job’s middleware() method. Here an AuthorizationException fails the job at once, and Laravel retries other exceptions up to the #[Tries(3)] limit.

<?php

namespace App\Jobs;

use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\Attributes\Tries;
use Illuminate\Queue\Middleware\FailOnException;

#[Tries(3)]
class SyncCustomerToCrm implements ShouldQueue
{
    use Queueable;

    public function __construct(public int $customerId)
    {
    }

    public function handle(): void
    {
        // Call the CRM API
    }

    /**
     * Get the middleware the job should pass through.
     *
     * @return array<int, object>
     */
    public function middleware(): array
    {
        return [
            new FailOnException([AuthorizationException::class]),
        ];
    }
}

A deleted model is a different case. If a job’s Eloquent model no longer exists when the job runs, #[DeleteWhenMissingModels] makes Laravel quietly discard the job without raising an exception. Laravel deletes the job instead of failing it, so it never reaches the failed-job workflow. Use it only when a missing record means the work is no longer needed.

If a flaky third-party API is the cause, attach ThrottlesExceptions middleware. In new ThrottlesExceptions(10, 5 * 60), the first argument is how many exceptions the job can throw before throttling starts. The second is the seconds to wait before the throttled job runs again. Below the threshold, the job is usually retried immediately unless you call backoff() on the middleware.

This is a throttle, not a cap of 10 executions. Laravel keeps retrying the job until its limits end it. The docs say to typically pair it with time-based attempts, using retryUntil() to return the time after which Laravel stops attempting the job. If a job defines both retryUntil() and #[Tries], Laravel gives precedence to retryUntil(), so the two do not work as independent limits.

3. Set timeouts that do not cause double runs

The default timeout is 60 seconds. Set a per-job value with #[Timeout(30)], as in the first example. Keep the timeout at least several seconds shorter than the connection’s retry_after value in config/queue.php. The stock Redis connection sets retry_after to 90 seconds, so a 120-second timeout there would let a second worker start the same job. If a job needs more than 90 seconds, raise retry_after first. Once retry_after passes, the queue releases the job back onto the queue even if the first worker is still running it, and another worker can pick it up. A shorter timeout makes sure Laravel terminates a frozen job before that happens.

Amazon SQS is the exception. It has no retry_after value and uses the queue’s Default Visibility Timeout, which you manage in the AWS console. Add #[FailOnTimeout] to fail a timed-out job instead of retrying it. Job timeouts also need the PCNTL PHP extension.

4. Get alerted when a job finally fails

The failed() method in the first example runs after the last attempt. If the job fails by running out of attempts, the exception is a MaxAttemptsExceededException. If it times out, it is a TimeoutExceededException. Laravel builds a new instance of the job before calling failed(), so property changes made in handle() are gone. For one alert covering every job, register Queue::failing() in the boot method of AppServiceProvider.

5. Diagnose, fix, then replay or discard

Where failures are stored depends on the failed-job driver in config/queue.php. The failed_jobs database table is the usual setup. Laravel also supports DynamoDB, and the null driver discards failures without storing them. Laravel never stores jobs dispatched synchronously, because the application handles their exceptions immediately.

queue:failed lists each failed job’s ID, connection, queue, and failure time. Before retrying, inspect the recorded exception in the failed-job record, your application logs, or your monitoring tools. Fix the cause first. Then deploy the fix and run php artisan queue:restart, because long-lived workers do not notice code changes until they restart. Replay only after that.

# List failed jobs
php artisan queue:failed

# After deploying a fix, restart workers so they load the new code
php artisan queue:restart

# Retry one failed job by ID
php artisan queue:retry ce7bb17c-cdd8-41f0-a8ec-7b4fef4e5ece

# Retry every failed job on one queue, or all of them
php artisan queue:retry --queue=name
php artisan queue:retry all

# Delete one failed job record
php artisan queue:forget 91401d2c-0784-4f43-824c-34f94a33c24d

# Delete every failed job record, or only those that failed 48 or more hours ago
php artisan queue:flush
php artisan queue:flush --hours=48

# Delete failed job records older than 24 hours (the default), or older than 48 hours
php artisan queue:prune-failed
php artisan queue:prune-failed --hours=48

Under Horizon, use horizon:forget instead of queue:forget.

6. Make jobs safe to run more than once

A job can finish an external action and still fail before Laravel records success. The retry then repeats the action. Make important jobs idempotent, so running them twice creates no duplicate results. Check whether an order or payment already exists before creating it. Use the external service’s idempotency keys where it offers them. For jobs triggered by webhooks, see Stagebit’s answer on idempotent webhook processing in Laravel. A database transaction cannot undo an action an external service has already completed.

Check this before you retry anything

  • Side effects repeat. A job that charged a card or sent an email before it failed can do both again. Step 6 covers the fix.
  • Retry all refills the table.queue:retry all requeues every failed job, so one unfixed bug sends them all back to failed-job storage.

Which fix should you start with?

Match the fix to the failure. Use a tries cap and backoff for temporary errors and fail() or dontRetry for permanent ones. Add a failed() alert so no final failure goes unseen. Retries recover from bad luck. Only removing the cause stops the loop. If you want a second set of eyes on a queue setup, see Stagebit’s Laravel development services.

Was this answer helpful?

Your feedback helps us improve our answers.

Still need help?

Questions about Laravel jobs that keep failing?

If you're weighing how to handle retries, backoff, and failed-job alerts in your Laravel queue, we're happy to walk through what you're seeing and what your options are.

Talk to Laravel Experts