Skip to content
betterstack-alchemyUnofficial

Incidents.SendHeartbeat

Kind BindingType id BetterStack.Incidents.SendHeartbeatSource src/Incidents/SendHeartbeat.ts

Ping an Heartbeat from running code: “the job ran”. The heartbeat stays pending until the first ping; after that, a ping missing for its period plus grace opens an incident and notifies whoever the heartbeat’s alert settings and escalation policy name.

Credential. The host receives the heartbeat’s secret url (Redacted, as BETTERSTACK_HEARTBEAT_<HEARTBEAT>_URL) and nothing else: the URL is the whole credential, needs no API token, and can only ping that one heartbeat. That is the least there is.

Cost. None per ping. A ping never notifies anyone; a missing one does.

Provide SendHeartbeatHttp on the host’s implementation. For a job that can fail, heartbeatJob pings on success and reports the failure otherwise.

Ping every minute from a background Service

export const WorkerAlive = BetterStack.Incidents.Heartbeat("WorkerAlive", { period: 60, grace: 60 });
export default class Worker extends BetterStack.Cloud.Service<Worker>()(
"Worker",
{ server: Box, main: import.meta.url },
Effect.gen(function* () {
const alive = yield* BetterStack.Incidents.SendHeartbeat(WorkerAlive);
const inHost = yield* BetterStack.withHostRuntime;
const host = yield* ServerHost;
yield* host.run(
inHost(alive().pipe(Effect.ignore, Effect.repeat(Schedule.spaced("1 minute")), Effect.asVoid)),
);
}).pipe(Effect.provide(BetterStack.Incidents.SendHeartbeatHttp)),
) {}

The same binding works on any Alchemy host: on a Cloudflare Worker’s cron trigger, yield* alive() at the end of the scheduled handler.