peppa/apps/web/instrumentation.ts
Асель 1085474c78 PEP-20: service monitoring — health, heartbeats, alerts to platform admins
- web/bot/watchdog heartbeats in settings (heartbeat:<service>)
- watchdog checks bot+web, bot checks watchdog+web; quiet > 5 min → Telegram alert
  to platform admins via outbox (platform.admins, default allowlist), recovery message,
  hourly reminder, 15 min cooldown, deterministic dedupe; watchdog sends directly
  when the bot is down
- GET /api/health (DB, version, services; 503 without DB)
- peppa status, peppa platform admins
- OpenSpec change pep-20-monitoring (archived), e2e monitor.test.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:06:54 +05:00

11 lines
502 B
TypeScript

// Runs once when the Next server starts: the web's heartbeat for service monitoring (PEP-20).
export async function register() {
if (process.env.NEXT_RUNTIME !== "nodejs") return;
const { beat } = await import("@peppa/core");
const { db } = await import("@/lib/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();
}