feat: add gateway restart tool

This commit is contained in:
Peter Steinberger
2025-12-25 18:05:37 +00:00
parent aafcd569b1
commit 42eb7640f9
6 changed files with 266 additions and 135 deletions

View File

@@ -515,7 +515,10 @@ const EVENTS = [
];
export type GatewayServer = {
close: () => Promise<void>;
close: (opts?: {
reason?: string;
restartExpectedMs?: number | null;
}) => Promise<void>;
};
export type GatewayServerOptions = {
@@ -5911,7 +5914,15 @@ export async function startGatewayServer(
}
return {
close: async () => {
close: async (opts) => {
const reasonRaw =
typeof opts?.reason === "string" ? opts.reason.trim() : "";
const reason = reasonRaw || "gateway stopping";
const restartExpectedMs =
typeof opts?.restartExpectedMs === "number" &&
Number.isFinite(opts.restartExpectedMs)
? Math.max(0, Math.floor(opts.restartExpectedMs))
: null;
if (bonjourStop) {
try {
await bonjourStop();
@@ -5947,8 +5958,8 @@ export async function startGatewayServer(
await stopTelegramProvider();
cron.stop();
broadcast("shutdown", {
reason: "gateway stopping",
restartExpectedMs: null,
reason,
restartExpectedMs,
});
clearInterval(tickInterval);
clearInterval(healthInterval);