Monitor the Laravel scheduler

Laravel's scheduler can ping a URL when a task succeeds or fails, so each task takes one line to monitor. One more check watches the scheduler itself, because if its cron entry is gone, no task runs and none of them pings.

You need: a Lateping account, a Laravel app with scheduled tasks, about 10 minutes.

What can go wrong

Laravel runs every scheduled task from one cron entry, php artisan schedule:run, every minute. That single line is the weak point, and task failures are easy to miss too.

Set it up

  1. Create the checks

    Create one check per scheduled task, with the same schedule and timezone, and one more for the scheduler itself: every 5 minutes, grace 5 minutes. Put the ping URLs in .env.

    .env
    LATEPING_REPORTS=https://lateping.com/p/<check-id>
    LATEPING_SCHEDULER=https://lateping.com/p/<check-id>
    

    Read them through config (for example config/services.php), not with env() in routes/console.php, so they still work when the configuration is cached.

  2. Ping from each task

    routes/console.php
    <?php
    
    use Illuminate\Support\Facades\Schedule;
    
    $reports = config('services.lateping.reports');
    
    // One check per task: /start when it begins, the URL on success, /fail on failure.
    Schedule::command('reports:generate')
        ->dailyAt('02:17')
        ->timezone('UTC')
        ->pingBefore("{$reports}/start")
        ->pingOnSuccess($reports)
        ->pingOnFailure("{$reports}/fail");
    
    // The scheduler's own heartbeat: if schedule:run stops, these pings stop and the check alerts.
    Schedule::exec('true')
        ->everyFiveMinutes()
        ->evenInMaintenanceMode()
        ->pingOnSuccess(config('services.lateping.scheduler'));
    
    config/services.php
    'lateping' => [
        'reports' => env('LATEPING_REPORTS'),
        'scheduler' => env('LATEPING_SCHEDULER'),
    ],
    
    • pingOnSuccess and pingOnFailure decide by the command’s exit code, so return a non-zero exit (return Command::FAILURE;) when a task fails.
    • The heartbeat uses evenInMaintenanceMode(), so it tells you the scheduler runs, not whether the app is up. Leave it off the real tasks if you want maintenance mode to skip them.
    • If the scheduler stops, every check goes late, and the heartbeat alerts first (after 5 to 10 minutes), which tells you it’s the scheduler, not the task.
  3. Check the cron entry and test

    Make sure the scheduler’s cron entry exists on the server that runs it, then run a task by hand. schedule:test runs one task now, pings included.

    crontab -e (as the app's user)
    * * * * * cd /var/www/app && php artisan schedule:run >> /dev/null 2>&1
    
    bash
    php artisan schedule:list
    php artisan schedule:test --name="reports:generate"
    

Notes

  • Several servers running the scheduler? Add ->onOneServer() to each task, or every server pings and a dead server goes unnoticed while another keeps the check green. Give the heartbeat one check per server instead, without onOneServer().
  • Queued tasks (Schedule::job(...)) are only dispatched by the scheduler; the work happens in a queue worker. Ping from the job’s handle() method at the end to know the work itself finished.
  • Because pingBefore sends /start, task runs are timed. Once a check has 10 timed runs, Pro and above also get an alert when a run is unusually short or long compared with the last 20. It is on by default and can be switched off in the check’s Settings tab. It does not catch a started job that never finishes. The heartbeat sends no /start, so it isn’t timed.
  • Alerts go by email. On Pro and above they can also go to Slack, Discord or a webhook.

Next steps

On this page