Cron job not running? See missed, failed and hung runs
"Not running" can mean three different things: the job never started, it started and failed, or it started and never finished. Wrap the job in pings to Buggregator: one at the start, one at the end with the job's output. Buggregator then marks each run as finished, failed, missed or timed out, and keeps the last 10 KB of what the job printed. You see which of the three happened, and why.
Steps
1. Start Buggregator with a database file
The default database lives in memory, so runs are gone after a restart.
buggregator -db buggregator.db2. Wrap the job in a small script
Save this as cron-run.sh and make it executable. It pings the start, runs your command, and sends its output as a success or a failure.
#!/bin/sh
# Usage: cron-run.sh <job-name> "<schedule>" <command> [args...]
B=http://127.0.0.1:8000
job=$1; schedule=$2; shift 2
log=$(mktemp)
curl -fsS -G "$B/ping/$job/start" --data-urlencode "schedule=$schedule" --data-urlencode "tz=UTC" > /dev/null
if "$@" > "$log" 2>&1; then
curl -fsS -X POST --data-binary @"$log" "$B/ping/$job" > /dev/null
else
curl -fsS -X POST --data-binary @"$log" "$B/ping/$job/fail" > /dev/null
fi
rm -f "$log"3. Use it in the crontab
Give the same schedule as the crontab line. Set tz in the script to the time zone your cron daemon uses; Buggregator reads the schedule in UTC by default.
0 2 * * * /opt/cron-run.sh backup "0 2 * * *" /opt/backup.sh4. Read the status
Open http://127.0.0.1:8000, then Sentry → Crons. Jobs that failed, hung or missed a run come first, under Needs attention. Open a job for its runs and the output each run sent.
| Status | What it means | Where to look |
|---|---|---|
missed |
the run was due and no ping came | the crontab line, the cron daemon, the schedule and time zone |
| Failed | the command exited with an error | the run's output |
| Timed out | the run started and did not finish within max_runtime |
a lock, a stuck network call, a too small limit |
ok |
the run finished fine | nothing |
A run counts as missed when nothing comes within the margin after it was due: 1 minute by default. A run counts as hung after 30 minutes by default. Change both in the start ping with margin and max_runtime, in whole minutes.
Why it works
The start ping carries the schedule, so Buggregator knows when the next run is due. Every 30 seconds it checks each job. A due run with no ping becomes missed, and a started run older than max_runtime becomes timeout. A POST body is kept as the run's output, the last 10 KB. Buggregator shows this in the UI and sends no alerts.
Docs: docs.buggregator.dev/config/crons.html#missed-and-hung-runs
Requires Buggregator v2.13.0+
Related tips
- Crons
Know when a cron script did not run: one curl line
Add a curl to your crontab line. Buggregator shows each run, marks missed and hung runs, and keeps the last 10 KB of the job's output.
- Crons
Know when a Laravel scheduled task did not run
Add ->sentryMonitor() to a scheduled task and point the Sentry DSN at Buggregator. Each run shows up, and missed or hung runs are marked.
- Crons
Python cron jobs with Sentry's @monitor, locally
Point sentry_sdk at Buggregator and keep your @monitor decorator. Every run shows up, and Buggregator marks missed and hung runs. No Sentry account.
Checked on with Buggregator v2.13.0