Start free trial
Start free trial Log in

14-day free trial. No credit card.

How to Monitor Laravel Scheduled Tasks in Production

Scheduled tasks fail silently by default, so here's how to find out when they do.

  • Guide
  • 3 min read

How do I know if my Laravel scheduled tasks are running?

Laravel's scheduler has no built-in alerting for silent failures. To catch a task that never ran, use a dead-man's-switch service (Healthchecks.io, Cronitor) called via pingOnSuccess. To see how each run went, listen to the ScheduledTaskFinished and ScheduledTaskFailed events, or use an APM like NightOwl or Nightwatch Cloud that records every run with its duration, status and exception.

Updated

Scheduled tasks are the part of an app that's supposed to run when nobody's looking, which is exactly the problem: nobody's looking. A web request that breaks throws an error someone sees in seconds. A nightly invoice job that stops running breaks in total silence. Nothing returns a 500 and nobody complains in the moment; the work just doesn't happen. You find out days later when the numbers don't add up. Monitoring scheduled tasks is almost entirely about detecting absence: knowing that something which should have run, didn't.

Why tasks fail silently

Laravel's scheduler runs as a single cron entry:

Terminal
* * * * * cd /srv/app && php artisan schedule:run >> /dev/null 2>&1

If that cron stops running (because cron is down, the filesystem is full, the deploy script broke the crontab, or schedule:run crashes before reaching your task), every scheduled task in your app stops. And you'll find out the next time a report is missing or a subscription didn't renew.

Option 1: Dead-man's switch per task

Services like Healthchecks.io, Cronitor, and Oh Dear give you URLs that expect pings on a schedule. Miss a ping, get paged.

routes/console.phpphp
use Illuminate\Support\Facades\Schedule;

Schedule::command('app:generate-invoices')
    ->dailyAt('01:00')
    ->onOneServer()
    ->withoutOverlapping(10)
    ->pingBefore('https://hc-ping.com/xxxxxxxx-invoices/start')
    ->pingOnSuccess('https://hc-ping.com/xxxxxxxx-invoices')
    ->onFailure(fn () => logger()->error('Invoices job failed'));

Works reliably. The downside: one URL per task (tedious at 20+ tasks), and you only learn that a task failed. You don't get the exception, the stack trace or how its duration has been trending.

Option 2: Scheduler events

Laravel dispatches an event at each stage of a scheduled task's run: ScheduledTaskStarting, ScheduledTaskFinished, ScheduledTaskFailed and ScheduledTaskSkipped. Listen and log to any destination.

app/Providers/AppServiceProvider.phpphp
use Illuminate\Console\Events\ScheduledTaskFinished;
use Illuminate\Console\Events\ScheduledTaskFailed;
use Illuminate\Support\Facades\Event;

public function boot(): void
{
    Event::listen(ScheduledTaskFinished::class, function ($event) {
        logger()->info('Scheduled task finished', [
            'task' => $event->task->command ?? $event->task->description,
            'runtime' => $event->runtime,
        ]);
    });

    Event::listen(ScheduledTaskFailed::class, function ($event) {
        logger()->error('Scheduled task failed', [
            'task' => $event->task->command ?? $event->task->description,
            'exception' => $event->exception->getMessage(),
        ]);
    });
}

Pipes through any Laravel log channel. Flexible, but you still need a destination that indexes, groups, and alerts on these log lines. Raw logs in a file aren't a monitoring system.

Prevent overlap and split across servers

Two chainable calls every production app should use:

php
Schedule::command('reports:generate')
    ->hourly()
    // Only one server in the cluster runs it (needs a shared database,
    // Redis, Memcached or DynamoDB cache store)
    ->onOneServer()
    // If the task is still running from last hour, skip this invocation.
    // The integer is the lock timeout in minutes. Without it the lock lasts
    // 1440 minutes, so a crashed task can block runs for up to a day.
    ->withoutOverlapping(120);

What to alert on

In order of value:

  1. Scheduler didn't run at all: highest-priority. Use a dead-man's switch on the schedule:run command itself, not just individual tasks.
  2. Task failed: group by task name, alert on threshold (e.g. 3 failures in 1 hour), not every occurrence.
  3. Task duration spiked: the report job that used to take 30s now takes 8 minutes. Use p95 trending, not single-invocation thresholds.
  4. Task didn't run on expected cadence: hourly task missed an hour. Needs history, not just current-state.

Know when a scheduled task fails or slows down

NightOwl records every finished, failed or skipped run with its duration and exception, on one page per task. A failing task opens one issue and alerts you when it's new or reopens, not on every run. It can't see a task that never ran, so keep a dead-man's switch on the scheduler too.

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

How do I know if my Laravel scheduled tasks are running?

Laravel's scheduler runs tasks via a single cron entry that calls schedule:run every minute. If that cron is broken, silently fails, or the box is down, your tasks stop running with no notification by default. Options: pingBefore and pingOnSuccess (or thenPing) to a dead-man's-switch service, Laravel's built-in events, or an APM that logs every task invocation.

Why did my Laravel scheduled task stop running silently?

Four common causes: (1) the cron service on the server is stopped, (2) the schedule:run command is crashing before it reaches your task, (3) another task is blocking the scheduler process, (4) the task has a withoutOverlapping lock that didn't release. You won't know unless you monitor invocations, not just the task code.

What's a dead-man's-switch for Laravel scheduled tasks?

A dead-man's switch is a service (Healthchecks.io, Cronitor, Oh Dear) that expects a ping on a schedule. If the ping doesn't arrive, it alerts you. Wire it to Laravel with ->pingOnSuccess('https://...'). The downside: you have to configure one endpoint per task, and you only learn that a task failed, not why.

How do I log Laravel scheduled task runs?

Hook into the scheduler's events: ScheduledTaskStarting, ScheduledTaskFinished, ScheduledTaskFailed and ScheduledTaskSkipped. ScheduledTaskFinished carries the runtime, and $event->task->exitCode holds a command task's exit code. Log those to a table or send to an APM. Laravel Nightwatch records finished, failed and skipped runs automatically (not Starting), and NightOwl stores them with full history. The exit code isn't recorded.

How do I prevent scheduled tasks from overlapping?

Chain ->withoutOverlapping() on the schedule definition. This uses the cache to hold a lock while the task runs. You can pass a timeout: withoutOverlapping(10) releases the lock after 10 minutes even if the process hangs. Without an argument the lock expires after 1440 minutes, so a crashed task can block its next runs for up to a day.

Should scheduled tasks run on one server or all servers?

Chain ->onOneServer() when running the scheduler on multiple machines behind a load balancer. It uses a lock in the cache so only one server runs the task. The default cache store must be database, Redis, Memcached or DynamoDB, and every server must use the same one. The default database store works if all servers share the database; the file store doesn't, because it's per-server.

How do I alert when a scheduled task fails?

Use ->onFailure(fn() => ...) in the schedule definition, or listen to ScheduledTaskFailed events. For production, route alerts through something that groups noise. Per-task threshold alerts (e.g., 3 failures in an hour) work better than per-invocation pages, but you have to build that count yourself. NightOwl groups a failing task's exception into one issue and alerts when it's new or reopens, not on every failed run.

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

Related

See every run of your scheduled tasks

Each finished, failed or skipped run lands on its task's page with its duration. No credit card needed.