health: gateway-only status and stable reconnect
This commit is contained in:
@@ -183,12 +183,8 @@ export async function healthCommand(
|
|||||||
method: "health",
|
method: "health",
|
||||||
timeoutMs: opts.timeoutMs,
|
timeoutMs: opts.timeoutMs,
|
||||||
});
|
});
|
||||||
const fatal =
|
// Gateway reachability defines success; provider issues are reported but not fatal here.
|
||||||
!summary.web.linked ||
|
const fatal = false;
|
||||||
(summary.web.connect && !summary.web.connect.ok) ||
|
|
||||||
(summary.telegram.configured &&
|
|
||||||
summary.telegram.probe &&
|
|
||||||
!summary.telegram.probe.ok);
|
|
||||||
|
|
||||||
if (opts.json) {
|
if (opts.json) {
|
||||||
runtime.log(JSON.stringify(summary, null, 2));
|
runtime.log(JSON.stringify(summary, null, 2));
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ export async function statusCommand(
|
|||||||
runtime.log(` ${line}`);
|
runtime.log(` ${line}`);
|
||||||
}
|
}
|
||||||
if (health) {
|
if (health) {
|
||||||
runtime.log(info("WA connect: reported by gateway (no direct probe)"));
|
runtime.log(info("Gateway health: reachable"));
|
||||||
|
|
||||||
const tgLine = health.telegram.configured
|
const tgLine = health.telegram.configured
|
||||||
? health.telegram.probe?.ok
|
? health.telegram.probe?.ok
|
||||||
|
|||||||
@@ -327,10 +327,10 @@ export async function runWebHeartbeatOnce(opts: {
|
|||||||
{ to, reason: "heartbeat-token", rawLength: replyPayload.text?.length },
|
{ to, reason: "heartbeat-token", rawLength: replyPayload.text?.length },
|
||||||
"heartbeat skipped",
|
"heartbeat skipped",
|
||||||
);
|
);
|
||||||
console.log(success("heartbeat: ok (HEARTBEAT_OK)"));
|
console.log(success("heartbeat: ok (HEARTBEAT_OK)"));
|
||||||
emitHeartbeatEvent({ status: "ok-token", to });
|
emitHeartbeatEvent({ status: "ok-token", to });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasMedia) {
|
if (hasMedia) {
|
||||||
heartbeatLogger.warn(
|
heartbeatLogger.warn(
|
||||||
@@ -369,8 +369,9 @@ export async function runWebHeartbeatOnce(opts: {
|
|||||||
);
|
);
|
||||||
console.log(success(`heartbeat: alert sent to ${to}`));
|
console.log(success(`heartbeat: alert sent to ${to}`));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
heartbeatLogger.warn({ to, error: String(err) }, "heartbeat failed");
|
const reason = String(err);
|
||||||
console.log(danger(`heartbeat: failed - ${String(err)}`));
|
heartbeatLogger.warn({ to, error: reason }, "heartbeat failed");
|
||||||
|
console.log(danger(`heartbeat: failed - ${reason}`));
|
||||||
emitHeartbeatEvent({ status: "failed", to, reason: String(err) });
|
emitHeartbeatEvent({ status: "failed", to, reason: String(err) });
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -1380,15 +1381,9 @@ export async function monitorWebProvider(
|
|||||||
reconnectAttempts,
|
reconnectAttempts,
|
||||||
maxAttempts: reconnectPolicy.maxAttempts,
|
maxAttempts: reconnectPolicy.maxAttempts,
|
||||||
},
|
},
|
||||||
"web reconnect: max attempts reached",
|
"web reconnect: max attempts reached; continuing in degraded mode",
|
||||||
);
|
);
|
||||||
runtime.error(
|
reconnectAttempts = 0;
|
||||||
danger(
|
|
||||||
`WhatsApp Web connection closed (status ${status}). Reached max retries (${reconnectPolicy.maxAttempts}); exiting so you can relink.`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await closeListener();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const delay = computeBackoff(reconnectPolicy, reconnectAttempts);
|
const delay = computeBackoff(reconnectPolicy, reconnectAttempts);
|
||||||
|
|||||||
Reference in New Issue
Block a user