Dead man's switch

Alarm when something stops happening. The absence of an event is the trigger.

Use this to
  • Page oncall if a background worker stops sending heartbeats for 5 minutes
  • Alert when a batch import hasn't reported progress in 10 minutes
  • Notify your team if a payment processor stops responding to health checks
  • Detect a stalled web crawler that should have finished its run by now
Code
Reset the timer on each heartbeat
// every heartbeat replaces the pending alarm
await dk.schedule("missed-heartbeat", {
  key: "worker_42",
  delay: "5m",
  onDuplicate: "replace",
});
The alarm fires only if heartbeats stop
dk.handle("missed-heartbeat", async ({ key }) => {
  // we got here because no heartbeat arrived in time
  await alerts.page("worker-silent", { worker: key });
});
npm install delaykit