Start free trial
Start free trial Log in

14-day free trial. No credit card.

How to monitor failed Laravel jobs in production

From the failed_jobs table to aggregated per-class failure rates: four layers, and when each is the right tool.

  • Guide
  • 3 min read

How do I monitor failed Laravel jobs?

Run php artisan queue:failed to list what has failed, listen to the JobFailed event in a service provider to dispatch alerts, and install a tool that groups failures by job class and charts them over time. Laravel's failed_jobs table captures the data; monitoring tools surface it. NightOwl groups every job attempt by class with status, duration, and retry history.

Updated

A failed job is a promise your app quietly broke. Something was supposed to happen out of band (an email, a charge, an export, an index update) and it didn't, and because it was already off the request path nobody was watching when it went wrong. The job lands in a table and sits there, and the gap between "a job failed" and "someone noticed" is however long it takes for the missing side effect to become a complaint. Monitoring failed jobs is about shrinking that gap, and about telling the difference between one flaky job and a job class that's quietly falling apart.

Layer 1: The failed_jobs table

Laravel stores failed jobs in the failed_jobs table by default. queue:failed lists every one of them:

Terminal
php artisan queue:failed
# lists all failed jobs with UUID, connection, queue, class, failed_at

php artisan queue:retry all
# retries every failed job

php artisan queue:retry 5c1d1234-...
# retries a specific job by UUID

php artisan queue:flush
# deletes all failed job records

This is fine for small apps. Once you're past a few failures per day, eyeballing the list stops working. You need aggregation.

Layer 2: Event listeners for alerts

Laravel fires Illuminate\Queue\Events\JobFailed when a job exhausts retries. Laravel 11 and 12 apps don't ship an EventServiceProvider, so listen in AppServiceProvider::boot():

app/Providers/AppServiceProvider.php

php
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;

public function boot(): void
{
    Event::listen(function (JobFailed $event) {
        Log::channel('slack')->error('Job failed', [
            'job' => $event->job->resolveName(),
            'queue' => $event->job->getQueue(),
            'exception' => $event->exception->getMessage(),
            'attempts' => $event->job->attempts(),
        ]);
    });
}

Pair with a Slack log channel in config/logging.php. You get a ping on every failure. Good enough for low-volume apps; noisy for anything bigger.

Layer 3: Per-class failed() handler

For class-specific cleanup or alerts, Laravel calls a failed() method on the job if present:

app/Jobs/SendWelcomeEmail.php

php
public function failed(?Throwable $exception): void
{
    // Mark the user as needing manual outreach
    $this->user->update(['onboarding_failed_at' => now()]);

    // Alert the customer success team
    CustomerSuccess::notify(new OnboardingEmailFailed($this->user, $exception));
}

Useful for side effects (cleanup, customer support notifications). Don't use it for monitoring. You'd be duplicating logic across every job class.

Layer 4: Aggregated failure rate per class

The real signal is failure rate trending, not individual failures. A job class that goes from 0.1% failure rate to 5% is in trouble, even if individual failures look routine.

Metrics to surface per job class:

  • Total attempts (count)
  • Success / released / failed breakdown
  • p50, p95, p99 duration
  • Failure rate over time (spike detection)
  • Most common exception fingerprint per class

Horizon covers part of this for Redis queues: throughput, average runtime and the failed-job list, with no percentiles or exception fingerprints. For percentiles, grouped exceptions and queue drivers other than Redis (database, SQS, Beanstalkd) you need an APM. NightOwl records every job attempt with class, duration, status, and exception, grouped by class for aggregate trends. It doesn't alert on failure rates: its job alerts fire when a job throws a new exception or a run crosses its duration threshold, so a per-class rate alert needs a scheduled check of your own.

Common failure patterns worth catching

  1. External API timeouts: wrap HTTP calls in Http::timeout(); retry with backoff rather than letting the whole job fail.
  2. Database deadlocks: retry the transaction; don't count deadlocks as real failures.
  3. Missing models: the Eloquent model passed to the job was deleted before a worker picked it up, so restoring it throws ModelNotFoundException. Set public $deleteWhenMissingModels = true; on jobs where that is expected.
  4. Memory exhaustion: jobs processing large collections should chunk with chunkById(). Tune worker --memory flag.
  5. Stale code on long-running workers: always queue:restart on deploy.

See which job classes fail, and why

NightOwl charts processed, released and failed attempts for every job class, on any queue driver. Open a failed attempt to read its exception and stack trace. A new exception opens an issue and alerts your Slack, Discord, email or webhook channel.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

Where do failed Laravel jobs go?

By default, Laravel writes failed jobs to the failed_jobs table (or the database configured in queue.failed). Each row contains the UUID, connection, queue, payload, exception, and failed_at. Jobs fail once they use up their allowed attempts (the job's $tries property, or the worker's --tries option, which defaults to 1) or pass their retryUntil deadline. Without monitoring, they sit there until someone runs php artisan queue:failed.

How do I get alerted when a Laravel job fails?

Three options from simplest to most robust: (1) listen to the Illuminate\Queue\Events\JobFailed event in a service provider and dispatch a Slack/email alert, (2) use a failed() method on the job class itself for per-class handling, (3) use a monitoring tool like NightOwl that groups failures by job class, charts failed attempts over time, and sends an alert when a job throws a new exception, without code changes.

What's the difference between a failed job and a released job?

A released job was attempted, errored, and pushed back onto the queue for retry. It hasn't used up its allowed attempts yet. A failed job has exhausted its retry budget and lives in failed_jobs permanently. Both are worth tracking: high release rates predict future failures, and failure-only dashboards miss flapping jobs that eventually succeed.

How do I retry all failed Laravel jobs?

php artisan queue:retry all. This dispatches every failed job back to the queue. You can target specific jobs by UUID (queue:retry <uuid>) or by queue (queue:retry --queue=emails). After retrying, jobs are removed from failed_jobs. If they fail again, they're re-added.

How do I detect stuck or slow Laravel jobs?

Two mechanisms. First, set timeout on the job class, and workers kill jobs that exceed it. Second, monitor per-class duration percentiles: a job class whose p95 duration jumps from 2s to 30s is stuck even if it technically completes. Horizon shows runtime per job for Redis queues, but not percentiles; NightOwl charts p50, p95 and p99 per job class across all drivers, and a duration threshold can alert you when a single run takes too long.

Should I use Horizon or a third-party tool for queue monitoring?

Horizon is excellent if you're on Redis: it shows queue depth, throughput, and worker status in real time. It doesn't monitor failed jobs aggregated over long windows, and it only works with Redis. For database, SQS, Beanstalkd, or multi-driver setups, you'll need a third-party APM like NightOwl that covers all drivers.

How do I avoid losing failed jobs on deploy?

Two things. First, keep queue.failed.driver on a persistent store (the default is 'database-uuids') so failed_jobs survives worker restarts. Second, always run php artisan queue:restart on deploy so long-running workers pick up your new code, since old workers can process jobs with stale code and fail unexpectedly. Supervisord/systemd handle the actual restart.

What exceptions cause Laravel jobs to fail?

Any exception thrown from handle() that isn't caught. Common culprits: HTTP timeouts on external APIs, database deadlocks, memory limits (especially for jobs processing large collections), and serialization failures on Eloquent models where the row was deleted. Structured monitoring groups these by fingerprint so you can see which cause dominates.

Related

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial