throttle repeated pg-boss errors; docker log rotation

This commit is contained in:
ai-chess
2026-10-22 05:54:43 +03:00
parent e4b5b8ada5
commit 6ee91d1a57
2 changed files with 19 additions and 1 deletions
+13 -1
View File
@@ -15,7 +15,19 @@ export type EvalJob = { gameId: string; ply: number };
export type FinalizeJob = { gameId: string }; export type FinalizeJob = { gameId: string };
export const boss = new PgBoss({ connectionString: config.databaseUrl, schema: "pgboss" } as any); 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() { export async function startBoss() {
await boss.start(); await boss.start();
+6
View File
@@ -5,6 +5,9 @@ services:
image: postgres:17-alpine image: postgres:17-alpine
container_name: chessai-db container_name: chessai-db
restart: unless-stopped restart: unless-stopped
logging:
driver: json-file
options: { max-size: "20m", max-file: "5" }
environment: environment:
POSTGRES_USER: chess POSTGRES_USER: chess
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-chess} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-chess}
@@ -28,6 +31,9 @@ services:
image: chessai:latest image: chessai:latest
container_name: chessai container_name: chessai
restart: unless-stopped restart: unless-stopped
logging:
driver: json-file
options: { max-size: "20m", max-file: "5" }
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy