mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 14:24:59 +00:00
fix(onboarding): wait for gateway before health
This commit is contained in:
@@ -17,7 +17,7 @@ import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { stylePromptTitle } from "../terminal/prompt-style.js";
|
||||
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js";
|
||||
import { CONFIG_DIR, resolveUserPath } from "../utils.js";
|
||||
import { CONFIG_DIR, resolveUserPath, sleep } from "../utils.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import type { NodeManagerChoice, OnboardMode, ResetScope } from "./onboard-types.js";
|
||||
|
||||
@@ -333,6 +333,38 @@ export async function probeGatewayReachable(params: {
|
||||
}
|
||||
}
|
||||
|
||||
export async function waitForGatewayReachable(params: {
|
||||
url: string;
|
||||
token?: string;
|
||||
password?: string;
|
||||
/** Total time to wait before giving up. */
|
||||
deadlineMs?: number;
|
||||
/** Per-probe timeout (each probe makes a full gateway health request). */
|
||||
probeTimeoutMs?: number;
|
||||
/** Delay between probes. */
|
||||
pollMs?: number;
|
||||
}): Promise<{ ok: boolean; detail?: string }> {
|
||||
const deadlineMs = params.deadlineMs ?? 15_000;
|
||||
const pollMs = params.pollMs ?? 400;
|
||||
const probeTimeoutMs = params.probeTimeoutMs ?? 1500;
|
||||
const startedAt = Date.now();
|
||||
let lastDetail: string | undefined;
|
||||
|
||||
while (Date.now() - startedAt < deadlineMs) {
|
||||
const probe = await probeGatewayReachable({
|
||||
url: params.url,
|
||||
token: params.token,
|
||||
password: params.password,
|
||||
timeoutMs: probeTimeoutMs,
|
||||
});
|
||||
if (probe.ok) return probe;
|
||||
lastDetail = probe.detail;
|
||||
await sleep(pollMs);
|
||||
}
|
||||
|
||||
return { ok: false, detail: lastDetail };
|
||||
}
|
||||
|
||||
function summarizeError(err: unknown): string {
|
||||
let raw = "unknown error";
|
||||
if (err instanceof Error) {
|
||||
|
||||
Reference in New Issue
Block a user