fix : correct api healthz
CI / Verify (push) Successful in 1m45s
CI / Build immutable images and deploy (push) Successful in 2m24s

This commit is contained in:
2026-10-02 18:57:43 +07:00 Unverified
parent df8c89914e
commit f5b432a496
11 changed files with 193 additions and 50 deletions
+15 -1
View File
@@ -10,7 +10,7 @@ import {
getLatestLunarisVersion,
processCatalogSync,
} from "@/lib/catalog/sync";
import { closeRedisClient } from "@/lib/redis/client";
import { closeRedisClient, discordWorkerHeartbeatKey, getRedisClient } from "@/lib/redis/client";
const RETRY_DELAYS_MS = [0, 30_000, 120_000, 600_000, 1_800_000] as const;
@@ -50,6 +50,17 @@ const client = new Client({
GatewayIntentBits.MessageContent,
],
});
let heartbeatTimer: ReturnType<typeof setInterval> | undefined;
async function writeHeartbeat(): Promise<void> {
if (!client.isReady()) return;
try {
const redis = await getRedisClient();
await redis.set(discordWorkerHeartbeatKey(), "1", "EX", 45);
} catch (cause) {
log("heartbeat_failed", { error: cause instanceof Error ? cause.message : String(cause) });
}
}
let pendingMessageUrl: string | null = null;
let runner: Promise<void> | null = null;
@@ -168,11 +179,14 @@ try {
await Promise.race([ready, stopped]);
if (!shutdown.signal.aborted) {
log("discord_ready", { userId: client.user?.id, channelId });
await writeHeartbeat();
heartbeatTimer = setInterval(() => { void writeHeartbeat(); }, 15_000);
await notify("worker ready", { userId: client.user?.id, channelId });
await stopped;
}
} finally {
shutdown.abort();
if (heartbeatTimer) clearInterval(heartbeatTimer);
client.destroy();
await Promise.resolve(runner).catch(() => undefined);
await Promise.all([closeDb(), closeRedisClient()]);