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();
|
||||
|
||||
@@ -5,6 +5,9 @@ services:
|
||||
image: postgres:17-alpine
|
||||
container_name: chessai-db
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options: { max-size: "20m", max-file: "5" }
|
||||
environment:
|
||||
POSTGRES_USER: chess
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-chess}
|
||||
@@ -28,6 +31,9 @@ services:
|
||||
image: chessai:latest
|
||||
container_name: chessai
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options: { max-size: "20m", max-file: "5" }
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
Reference in New Issue
Block a user