· 2 min read

How to know when a cron job silently stops

A failing cron job usually fails quietly. Learn how heartbeat check-ins catch jobs that never ran, ran late or crashed, with three lines added to your crontab.

The nightly backup has been failing since March. Nobody knew, because a cron job that does not run makes no noise at all. Logs only record what happens; they cannot record a job that never started.

That is the gap check-ins (also called heartbeats or dead-man's switches) fill. Instead of watching for errors, you watch for silence.

How a check-in works

  1. You tell the monitor how often the job should run — say every 24 hours — and how much grace to give it.
  2. The job calls a unique URL when it finishes successfully.
  3. If the call does not arrive in time, the monitor alerts you.

Because the alert is triggered by an absence, it catches every way a job can fail: the server rebooted, the crontab was overwritten during a deploy, the disk filled up, the script threw before logging anything, or the scheduler itself is not running.

Adding one to a crontab

Each check-in in Grafatsuki has its own ping URL. Call /start when the job begins, the plain URL when it succeeds, and /fail when it fails:

0 3 * * * curl -fsS https://your-garden/ping/abc123def456/start; \
  ./backup.sh && curl -fsS https://your-garden/ping/abc123def456 \
              || curl -fsS https://your-garden/ping/abc123def456/fail

Three states come out of it:

  • up — the last ping arrived on time;
  • late — the expected time plus grace has passed with no ping;
  • down — the job reported a failure, or stayed late for too long.

Sending /start as well lets you see how long each run took, and notice a job that started but never finished.

In a Laravel app

The scheduler is itself a cron job, so the most useful check-in is the one that proves schedule:run is alive. Ping it from a scheduled command that runs every few minutes, and give the check-in a matching interval. If the server's cron entry disappears, you hear about it within minutes, instead of noticing that a week of emails never went out.

For individual scheduled commands, ->pingBefore() and ->thenPing() on the schedule call the start and success URLs for you.

Choosing the grace period

  • Short, frequent jobs: grace of a few minutes.
  • Nightly jobs: grace of 30–60 minutes, because run times vary with data size.
  • Jobs that run "whenever there is work": monitor the queue depth as a metric instead.

Telling people

Late and down check-ins go to the same channels as your other alerts — email, Slack, Discord, Telegram or a webhook — once when they start, and once when they recover. If your customers depend on a job (reports, invoices, syncs), you can show it on your app's public status page by name.

A check-in takes two minutes to add. The first time it fires, it has paid for itself many times over. More in alerts and uptime.

cronuptimealerts

Keep reading

Plant your first app in five minutes

Free to start. One link, one token — or one prompt for your coding agent.