14 lines
689 B
TypeScript
14 lines
689 B
TypeScript
// Runs once when the Next server starts: the web's heartbeat for service monitoring (PEP-20)
|
|
// and the runner-client mode (PEP-21): the web enqueues runner commands, the watchdog runs them.
|
|
export async function register() {
|
|
if (process.env.NEXT_RUNTIME !== "nodejs") return;
|
|
const { beat } = await import("@peppa/core");
|
|
const { db } = await import("@/lib/db");
|
|
const { setRunnerClient } = await import("@peppa/runner");
|
|
setRunnerClient(true, db);
|
|
const version = process.env.NEXT_PUBLIC_PEPPA_VERSION;
|
|
const tick = () => beat(db, "web", { version }).catch((e) => console.error(`heartbeat: ${(e as Error).message}`));
|
|
void tick();
|
|
setInterval(tick, 60_000).unref();
|
|
}
|