Monitor and Control Schedules, Queues, and Errors in Laravel with Watchtower
Laravel Composer Pacakge #Laravel #Monitoring #Queues #Scheduler #Packages #PHP

Monitor and Control Schedules, Queues, and Errors in Laravel with Watchtower

3 min read Mohamed Said Mohamed Said

What Is Watchtower?

Watchtower is an MIT-licensed Laravel package that brings scheduled tasks, queues, jobs, and exceptions together on a single dashboard designed to run safely in production. Rather than just surfacing data, it lets you act on it: trigger a scheduled task on demand, bulk-retry failed jobs, and mark exceptions as resolved — all from one place.

It requires PHP 8.2+ and Laravel 11 or 12, and works with any queue driver (database, Redis, or SQS) without forcing a Redis dependency.

Three Dashboard Tabs

Schedule

Lists every scheduled task with its cron expression rendered in plain English, alongside run history, durations, and missed-run detection. A Run now button lets you dispatch any task immediately without touching the CLI.

Queues & Jobs

Displays live queue metrics next to the failed-jobs table. You can retry a single job or bulk-retry by exception type or time window — a significant time-saver when a downstream service blip takes out a whole batch.

Errors

Groups exceptions by type and count with full stack traces, request context, and job context. Each error group has resolve and reopen controls so your team can track which issues have been addressed.

Production Safety by Default

Recording every request and job in-band would add latency to the very app being monitored. Watchtower avoids this by deferring writes to Laravel's terminating() callback. High-traffic applications can reduce overhead further with a sampling rate that still captures every failure and every schedule run regardless of the sample setting.

Row sizes are bounded by field truncation, and a daily watchtower:prune command enforces per-type retention windows (30 days for schedule runs and exceptions, 7 days for queue records by default).

Most behaviour is controlled through environment variables:

WATCHTOWER_ENABLED=true
WATCHTOWER_DB_CONNECTION=monitoring
WATCHTOWER_SAMPLING_RATE=0.25
WATCHTOWER_AFTER_RESPONSE=true
WATCHTOWER_RETAIN_EXCEPTIONS=30

Setting WATCHTOWER_ENABLED=false acts as an instant kill switch, and ignore lists for jobs, commands, and exceptions keep noisy items off the dashboard.

Authorization

The dashboard is restricted to the local environment by default. To open it in other environments, define the viewWatchtower gate:

use Illuminate\Support\Facades\Gate;

Gate::define('viewWatchtower', function ($user) {
    return $user !== null && $user->isAdmin();
});

Alternatively, use the fluent callback on the Watchtower facade:

use Watchtower\Watchtower;

Watchtower::auth(fn ($request) => $request->user()?->isAdmin());

Unauthorized requests receive a 403 response.

Optional Alerts

Watchtower can send notifications when a scheduled task fails, a run is missed, or failed jobs exceed a threshold (25 within 60 minutes by default). Alerts are disabled until you set WATCHTOWER_ALERTS_ENABLED=true, and they support Slack, a generic webhook, or email.

The checks run via the watchtower:monitor command, which you add to your scheduler:

$schedule->command('watchtower:monitor')->everyFiveMinutes();

Key Takeaways

  • Unified dashboard for schedules, queues, jobs, and exceptions — no separate tools needed.
  • Actionable controls: run tasks on demand, bulk-retry failed jobs, resolve/reopen errors.
  • Driver-agnostic: works with database, Redis, or SQS queues.
  • Production-safe: deferred writes, configurable sampling, field truncation, and automatic pruning.
  • Gate-based access control consistent with Horizon and Telescope conventions.
  • Optional alerting via Slack, webhook, or email with a simple scheduler command.

Source: Laravel News — Monitor and Control Schedules, Queues, and Errors in Laravel with Watchtower

Found this useful?

Frequently Asked Questions

3 questions
Q01 Does Watchtower require Redis to work?
No. Watchtower works with any Laravel queue driver — database, Redis, or SQS — and has no hard Redis dependency.
Q02 How does Watchtower avoid adding overhead to production requests?
Watchtower defers its writes to Laravel's terminating() callback so they happen after the response is sent. You can also configure a sampling rate so only a fraction of requests are recorded, while every failure and schedule run is always captured.
Q03 How do you restrict access to the Watchtower dashboard in production?
Define the viewWatchtower gate using Gate::define() or use the Watchtower::auth() fluent callback. Without either, the dashboard is only accessible in the local environment. Unauthorized requests receive a 403 response.

Continue reading

More Articles

View all