feat: add error handling for database connection pool to manage admin shutdown during backup windows
This commit is contained in:
parent
48768c0481
commit
70cc0e4536
1 changed files with 13 additions and 0 deletions
|
|
@ -26,6 +26,19 @@ const pool = new Pool({
|
||||||
user: env.POSTGRES_USER,
|
user: env.POSTGRES_USER,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pool.on("error", (err) => {
|
||||||
|
const pgErr = err as { code?: string };
|
||||||
|
// "admin_shutdown" error sent during backups
|
||||||
|
const isAdminShutdown = pgErr.code === "57P01";
|
||||||
|
const hour = new Date().getHours();
|
||||||
|
// Consider it a backup window if it's between 00:00 and 02:00
|
||||||
|
const isBackupWindow = hour === 0 || hour === 1;
|
||||||
|
|
||||||
|
if (isAdminShutdown && isBackupWindow) return;
|
||||||
|
|
||||||
|
console.error("PG error:", err);
|
||||||
|
});
|
||||||
|
|
||||||
type Db = typeof db;
|
type Db = typeof db;
|
||||||
|
|
||||||
type Trx = Transaction<PublicSchema>;
|
type Trx = Transaction<PublicSchema>;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue