A job has to prove it ran

At 06:30 on 17 November, our monitor marked one of our scheduled jobs as down and sent an alert to chat. The job hadn’t crashed. It hadn’t logged an error, returned a bad exit code or filled a disk. It simply never said it had finished. And for a small monitor we built in October, silence is the alarm.
This post is about that monitor, and about the idea behind it: a job has to prove it ran.
The problem with “no news”
A job that crashes loudly is the easy case. It writes a stack trace, exits with 1, maybe sends something angry somewhere. You notice.
The hard case is the job that doesn’t run at all. The scheduler skipped it. The machine was asleep. The script is waiting on a lock that will never open. Nothing writes an error, because nothing is running to write it. From the outside, a job that ran perfectly and a job that never started look exactly the same: quiet.
The usual fix is a dead man’s switch. The train driver has to keep holding the lever, and when the hand lets go the train stops. For jobs, it works the other way round from normal monitoring. Instead of waiting for a job to report a failure, the monitor waits for it to report success, and treats a missing report as the failure.
What we built
It’s a small service running on the same machine as the jobs. A job “pings” it with a tiny web request. There are four kinds of ping: start, success, fail, and an exit code, where 0 means success and anything else means failure. The address format copies Healthchecks.io, a hosted service built on the same idea, so moving a job between the two means changing one base address.
The end of one of our job scripts has this shape:
run_the_job
rc=$?
curl -fsS -m 10 -o /dev/null "$PING_URL" >/dev/null 2>&1 || true
exit $rc
The ping is the last thing the script does, and it can never break the job: if the monitor is down, the curl fails quietly and the job still exits with its own code. This one sends a bare success. Adding /$rc to the address would report the exit code too.
A few small decisions turned out to matter:
- A ping for an unknown check gets “not found”, not “OK”. A typo in a job’s check address is loud on day one instead of silently pinging nothing for a month.
- It only listens on the machine’s private address, and it refuses to start if told to listen anywhere else. No public endpoint, no accounts.
- Each check’s identifier is treated as a secret. The real list of checks stays out of the repository.
- It keeps the newest 100 pings per check. That’s enough to see a pattern and small enough to never think about.
Four states, worked out every minute
Every check is in one of four states. New means no success has arrived yet. Up means the last success came and the next one isn’t due. Late means the next one is due and hasn’t come. Down means the waiting time ran out, a run took too long, or the job reported a failure.
A check either expects a ping every fixed number of seconds, or follows a cron timetable. On top of that comes grace: extra waiting time after a ping was due before the check counts as down. Between the due time and the end of grace, the check is only late. Every 60 seconds the monitor moves checks from up to late, or from late to down, as the clock requires.
The cron kind matters more than it looks. The worked example from the design note was a job every 5 minutes from 08:00 to 23:55, with 15 minutes of grace. A last ping at 10:00 means late at 10:05 and down at 10:20. A last ping at 23:55 means no alert all night, because the timetable knows the next run is 08:00. A simple “every 5 minutes” check would wake someone up every night for a job that was working exactly as designed.
One more rule protects against the monitor itself. If it wasn’t running for more than five minutes (the computer slept, say), it pushes every deadline forward by one grace period instead of declaring everything down at once. Waking a laptop shouldn’t set off ten alarms.
One alert per change
A check going down produces exactly one alert. Coming back up produces one more. A check that stays down adds nothing. There’s no reminder every minute and no flood.
Each change goes into an outbox first, then to a notifier command. The command runs without a shell, so a strange check name can never turn into an instruction. If the notifier fails, the alert waits and tries again, first after 60 seconds, then doubling up to a cap of 30 minutes. An alert older than 24 hours is marked as handled without being sent, because a day-old “down” is noise, not news. And if the monitor dies halfway through sending, that one alert is lost rather than sent twice. We picked that trade on purpose.
There’s also a status page with one row per check: state, last ping, next due, down at, last alert. Its health endpoint reports the number of checks and the time of the last pass, and nothing that would reveal a path or an address.
Proving the monitor, too
A monitor nobody has seen fire is just another quiet thing. So before any real job was pointed at it, it got a canary: a tiny job whose only work is to ping every five minutes.
On 18 October, the day it started running at login, the test was to stop the canary on purpose. It was removed at 06:17:32. At 06:27:56 the check went down, ten minutes and 24 seconds later, within the window the period and grace allow. The canary went back at 06:29:01, and the check recovered. The alert log had exactly two lines, one down and one up.
The first real job was a check that runs every six hours to make sure another of our services is still receiving data. We added the ping as the last lines of its script. Its first scheduled pings came at 12:00:16, 18:00:15 and 00:00:15 that day and night, each within 16 seconds of the scheduled minute. Delivery to a chat channel I actually read came next, with a quiet hold at night, and it has been live since the start of November.
17 November
That morning, a macOS permission dialog popped up at 04:06 asking for access to an external disk. Nobody was awake to answer it. Until someone did, anything that tried to read from that disk just waited. It didn’t fail and didn’t time out. It waited.
As far as the logs show, the six-hourly job’s 06:00 run ran into it. Its process sat there, waiting for a permission nobody was going to give. It produced no output, no error and no exit code. It also produced no ping. At 06:30, when its 30 minutes of grace ran out, the check went down and the alert went out. Later that morning, at 08:10, the next ping arrived, and a second alert said the check had recovered.
Think about what would have caught this without the monitor. Error logs: nothing, there was no error. Exit-code alerting: nothing, the job never exited. Disk-usage graphs: nothing. The only signal anywhere was an absence, and absence is exactly what this tool is built to notice.
Where it stands
As of 19 November it watches two checks: that six-hourly job and the canary, and both are up. It has 195 tests. The code is a private repository for now, so there’s no link.
It also has a blind spot I can’t fix from inside the machine. If the computer is off or asleep, nothing on it can report that. The options are written down: accept the gap, pay for one external hosted check, or put a second device on watch. None is chosen yet.
And our pings are bare successes. They prove the script got to its last line, not that its work was correct. That’s a smaller promise than it sounds like, and I’d rather say so.
Still, the rule holds. Don’t wait for a job to complain. Make it check in, and treat silence as the loudest thing it can say.
— Max


