throttle repeated pg-boss errors; docker log rotation
This commit is contained in:
+13
-1
@@ -15,7 +15,19 @@ export type EvalJob = { gameId: string; ply: number };
|
||||
export type FinalizeJob = { gameId: string };
|
||||
|
||||
export const boss = new PgBoss({ connectionString: config.databaseUrl, schema: "pgboss" } as any);
|
||||
boss.on("error", (e: unknown) => logErr("pg-boss", e));
|
||||
// A DB outage makes every poll fail: log the first error in full, then one summary line per minute.
|
||||
let lastBossErr = { msg: "", at: 0, suppressed: 0 };
|
||||
boss.on("error", (e: unknown) => {
|
||||
const msg = e instanceof Error ? e.message : String(e);
|
||||
const now = Date.now();
|
||||
if (msg === lastBossErr.msg && now - lastBossErr.at < 60_000) {
|
||||
lastBossErr.suppressed++;
|
||||
return;
|
||||
}
|
||||
if (msg === lastBossErr.msg) logErr("pg-boss", `${msg} (repeated ${lastBossErr.suppressed + 1}× in the last minute)`);
|
||||
else logErr("pg-boss", e);
|
||||
lastBossErr = { msg, at: now, suppressed: 0 };
|
||||
});
|
||||
|
||||
export async function startBoss() {
|
||||
await boss.start();
|
||||
|
||||
Reference in New Issue
Block a user