mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 22:40:21 +00:00
refactor: centralize account bindings + health probes
This commit is contained in:
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user