refactor: centralize account bindings + health probes

This commit is contained in:
Peter Steinberger
2026-01-17 01:13:46 +00:00
parent 99aba3a5c4
commit f14d622c0f
12 changed files with 877 additions and 164 deletions

View File

@@ -6,11 +6,12 @@ import { formatForLog } from "../ws-log.js";
import type { GatewayRequestHandlers } from "./types.js";
export const healthHandlers: GatewayRequestHandlers = {
health: async ({ respond, context }) => {
health: async ({ respond, context, params }) => {
const { getHealthCache, refreshHealthSnapshot, logHealth } = context;
const wantsProbe = params?.probe === true;
const now = Date.now();
const cached = getHealthCache();
if (cached && now - cached.ts < HEALTH_REFRESH_INTERVAL_MS) {
if (!wantsProbe && cached && now - cached.ts < HEALTH_REFRESH_INTERVAL_MS) {
respond(true, cached, undefined, { cached: true });
void refreshHealthSnapshot({ probe: false }).catch((err) =>
logHealth.error(`background health refresh failed: ${formatError(err)}`),
@@ -18,7 +19,7 @@ export const healthHandlers: GatewayRequestHandlers = {
return;
}
try {
const snap = await refreshHealthSnapshot({ probe: false });
const snap = await refreshHealthSnapshot({ probe: wantsProbe });
respond(true, snap, undefined);
} catch (err) {
respond(false, undefined, errorShape(ErrorCodes.UNAVAILABLE, formatForLog(err)));