23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
// PEP-231: the watchdog keeps the platform's and the products' addresses on the server's tunnel
|
|
// (core/edge-dns.ts). Every 5 minutes; a no-op without CLOUDFLARE_* in env.
|
|
import { edgeConfig, edgeHosts, formatEdgeSync, syncEdge, type EdgeSyncResult } from "@peppa/core";
|
|
import type { Db } from "@peppa/db";
|
|
|
|
const EVERY_MS = 5 * 60_000;
|
|
let last = 0;
|
|
let lastReport = "";
|
|
|
|
export async function edgeDnsTick(db: Db, o: { now?: Date; log?: (m: string) => void; force?: boolean } = {}): Promise<EdgeSyncResult | null> {
|
|
const cfg = edgeConfig();
|
|
if (!cfg) return null;
|
|
const now = (o.now ?? new Date()).getTime();
|
|
if (!o.force && now - last < EVERY_MS) return null;
|
|
last = now;
|
|
const r = await syncEdge(cfg, await edgeHosts(db, cfg.domain, { now }));
|
|
// Only changes and new conflicts go to the log: the same conflict every 5 minutes is noise.
|
|
const report = formatEdgeSync(r);
|
|
if (r.created.length || r.moved.length || r.ingress === "set" || (r.conflicts.length && report !== lastReport)) o.log?.(`edge dns: ${report.replace(/\n/g, "; ")}`);
|
|
lastReport = report;
|
|
return r;
|
|
}
|