Update backup system and local changes
Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 21s
Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 21s
- BorgBackup disaster recovery system - Health endpoint updates - Merged with remote changes
This commit is contained in:
parent
ef84279eae
commit
7e74f22ea3
2 changed files with 68 additions and 13 deletions
|
|
@ -1,21 +1,55 @@
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { getPoolStats } from "../services/browser.js";
|
import { getPoolStats } from "../services/browser.js";
|
||||||
|
import { pool } from "../services/db.js";
|
||||||
|
|
||||||
export const healthRouter = Router();
|
export const healthRouter = Router();
|
||||||
|
|
||||||
healthRouter.get("/", (_req, res) => {
|
healthRouter.get("/", async (_req, res) => {
|
||||||
const pool = getPoolStats();
|
const poolStats = getPoolStats();
|
||||||
res.json({
|
let databaseStatus: any;
|
||||||
status: "ok",
|
let overallStatus = "ok";
|
||||||
|
let httpStatus = 200;
|
||||||
|
|
||||||
|
// Check database connectivity
|
||||||
|
try {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
const result = await client.query('SELECT version()');
|
||||||
|
const version = result.rows[0]?.version || 'Unknown';
|
||||||
|
// Extract just the PostgreSQL version number (e.g., "PostgreSQL 15.4")
|
||||||
|
const versionMatch = version.match(/PostgreSQL ([\d.]+)/);
|
||||||
|
const shortVersion = versionMatch ? `PostgreSQL ${versionMatch[1]}` : 'PostgreSQL';
|
||||||
|
|
||||||
|
databaseStatus = {
|
||||||
|
status: "ok",
|
||||||
|
version: shortVersion
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
databaseStatus = {
|
||||||
|
status: "error",
|
||||||
|
message: error.message || "Database connection failed"
|
||||||
|
};
|
||||||
|
overallStatus = "degraded";
|
||||||
|
httpStatus = 503;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
status: overallStatus,
|
||||||
version: "0.2.1",
|
version: "0.2.1",
|
||||||
|
database: databaseStatus,
|
||||||
pool: {
|
pool: {
|
||||||
size: pool.poolSize,
|
size: poolStats.poolSize,
|
||||||
active: pool.totalPages - pool.availablePages,
|
active: poolStats.totalPages - poolStats.availablePages,
|
||||||
available: pool.availablePages,
|
available: poolStats.availablePages,
|
||||||
queueDepth: pool.queueDepth,
|
queueDepth: poolStats.queueDepth,
|
||||||
pdfCount: pool.pdfCount,
|
pdfCount: poolStats.pdfCount,
|
||||||
restarting: pool.restarting,
|
restarting: poolStats.restarting,
|
||||||
uptimeSeconds: Math.round(pool.uptimeMs / 1000),
|
uptimeSeconds: Math.round(poolStats.uptimeMs / 1000),
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
});
|
|
||||||
|
res.status(httpStatus).json(response);
|
||||||
|
});
|
||||||
21
src/routes/health.ts.backup
Normal file
21
src/routes/health.ts.backup
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { Router } from "express";
|
||||||
|
import { getPoolStats } from "../services/browser.js";
|
||||||
|
|
||||||
|
export const healthRouter = Router();
|
||||||
|
|
||||||
|
healthRouter.get("/", (_req, res) => {
|
||||||
|
const pool = getPoolStats();
|
||||||
|
res.json({
|
||||||
|
status: "ok",
|
||||||
|
version: "0.2.1",
|
||||||
|
pool: {
|
||||||
|
size: pool.poolSize,
|
||||||
|
active: pool.totalPages - pool.availablePages,
|
||||||
|
available: pool.availablePages,
|
||||||
|
queueDepth: pool.queueDepth,
|
||||||
|
pdfCount: pool.pdfCount,
|
||||||
|
restarting: pool.restarting,
|
||||||
|
uptimeSeconds: Math.round(pool.uptimeMs / 1000),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue