fix : correct api healthz
This commit is contained in:
+15
-1
@@ -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()]);
|
||||
|
||||
Reference in New Issue
Block a user