Monitor a Node job.
One fetch after the work, with a timeout. Five minutes, start to finish.
Before you start
You need a heartbeat in Upglory with its period and grace set to match the schedule that starts the script, whatever starts it. Its page shows the ping address; pass it to the script as UPGLORY_PING_URL.
Settings that match this schedule
- Period6 hoursThe schedule the script is started on, whatever starts it.
- Grace15 minutesThe longest run you have seen, plus a little.
- Channelsemail, TelegramInherited from the workspace default. Change it on this heartbeat if it matters less than the others.
The line
Send the ping as the last thing the job does. If the work throws, the ping is never sent, which is exactly what you want.
// after the work, never before it
const PING_URL = process.env.UPGLORY_PING_URL;
async function ping(path = "") {
await fetch(PING_URL + path, { signal: AbortSignal.timeout(10_000) });
}
await rebuildSitemap();
await ping(); AbortSignal.timeout is the part people leave out: without it a hung ping can outlive the job it was reporting on.
Measure the run time
Ping /start before the work. The ping after it then records how long the job ran, and a slow run is not mistaken for a missed one.
await ping("/start");
await rebuildSitemap();
await ping();Report a failure
Ping /fail in the catch and throw again: you hear about the failure at once instead of at the end of the grace window, and the job still exits with its error.
try {
await rebuildSitemap();
await ping();
} catch (err) {
await ping("/fail");
throw err;
}Test it
Use Send a test ping on the heartbeat's page, or run the script once by hand. Nothing alerts until the first ping arrives, so a job you have not deployed yet never raises an alarm.
What you will see if it stops
Fifteen minutes after the run was due, the heartbeat turns down. If the script pinged /fail instead, the alert arrives immediately and says the job reported a failure rather than going quiet, which are two different problems.
last ping 06:02, ran 2 min 5 s
Email and Telegram told at 12:15