/** * Every few minutes: flapping alerts that have been quiet for an hour have settled — say so once, with the state each is in now (see services/flapGuard.ts). */ import { getAlerts } from "./alerts.js"; import { keyOfAlertId, settleFlaps } from "./flapGuard.js"; import { notifySettled } from "./notify.js"; /** One look: returns how many settled. */ export async function settleFlappingAlerts(now: Date = new Date()): Promise { const report = await getAlerts(false); const active = new Set(report.alerts.map((a) => keyOfAlertId(a.id, a.category))); const settled = await settleFlaps(active, now); if (settled.length > 0) await notifySettled(settled); return settled.length; } let timer: ReturnType | null = null; export function initFlapMonitor(): void { if (timer) return; timer = setInterval(() => void settleFlappingAlerts().catch((err) => console.error("[flap] couldn't look at the flapping alerts:", err)), 5 * 60_000); timer.unref(); }