mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-18 20:41:36 +00:00
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
// Gateway startup-time runtime services.
|
|
// Starts mode-dependent background monitors with inert handles for disabled paths.
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import type { ChannelHealthMonitor } from "./channel-health-monitor.js";
|
|
import { startChannelHealthMonitor } from "./channel-health-monitor.js";
|
|
import {
|
|
createNoopHeartbeatRunner,
|
|
type GatewayRuntimeServiceLogger,
|
|
} from "./server-runtime-service-shared.js";
|
|
|
|
// Runtime startup services start only the background services needed by the
|
|
// current gateway mode. Channel health is configurable; heartbeat/model pricing
|
|
// currently use inert handles here and are wired by other startup paths.
|
|
export type GatewayChannelManager = Parameters<
|
|
typeof startChannelHealthMonitor
|
|
>[0]["channelManager"];
|
|
|
|
/** Starts channel health monitoring when gateway config enables it. */
|
|
export function startGatewayChannelHealthMonitor(params: {
|
|
cfg: OpenClawConfig;
|
|
channelManager: GatewayChannelManager;
|
|
}): ChannelHealthMonitor | null {
|
|
const healthCheckMinutes = params.cfg.gateway?.channelHealthCheckMinutes;
|
|
if (healthCheckMinutes === 0) {
|
|
return null;
|
|
}
|
|
const staleEventThresholdMinutes = params.cfg.gateway?.channelStaleEventThresholdMinutes;
|
|
const maxRestartsPerHour = params.cfg.gateway?.channelMaxRestartsPerHour;
|
|
return startChannelHealthMonitor({
|
|
channelManager: params.channelManager,
|
|
checkIntervalMs: (healthCheckMinutes ?? 5) * 60_000,
|
|
...(staleEventThresholdMinutes != null && {
|
|
staleEventThresholdMs: staleEventThresholdMinutes * 60_000,
|
|
}),
|
|
...(maxRestartsPerHour != null && { maxRestartsPerHour }),
|
|
});
|
|
}
|
|
|
|
/** Starts background runtime services and returns their stop/update handles. */
|
|
export function startGatewayRuntimeServices(params: {
|
|
minimalTestGateway: boolean;
|
|
cfgAtStart: OpenClawConfig;
|
|
channelManager: GatewayChannelManager;
|
|
log: GatewayRuntimeServiceLogger;
|
|
}): {
|
|
heartbeatRunner: ReturnType<typeof createNoopHeartbeatRunner>;
|
|
channelHealthMonitor: ChannelHealthMonitor | null;
|
|
stopModelPricingRefresh: () => void;
|
|
} {
|
|
const channelHealthMonitor = startGatewayChannelHealthMonitor({
|
|
cfg: params.cfgAtStart,
|
|
channelManager: params.channelManager,
|
|
});
|
|
|
|
return {
|
|
heartbeatRunner: createNoopHeartbeatRunner(),
|
|
channelHealthMonitor,
|
|
stopModelPricingRefresh: () => {},
|
|
};
|
|
}
|