From 7e74f22ea393c60eb89fcf0a1de37da9fa764524 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sun, 15 Feb 2026 11:04:58 +0000 Subject: [PATCH] Update backup system and local changes - BorgBackup disaster recovery system - Health endpoint updates - Merged with remote changes --- src/routes/health.ts | 60 +++++++++++++++++++++++++++++-------- src/routes/health.ts.backup | 21 +++++++++++++ 2 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 src/routes/health.ts.backup diff --git a/src/routes/health.ts b/src/routes/health.ts index bbee73a..5d27dbb 100644 --- a/src/routes/health.ts +++ b/src/routes/health.ts @@ -1,21 +1,55 @@ import { Router } from "express"; import { getPoolStats } from "../services/browser.js"; +import { pool } from "../services/db.js"; export const healthRouter = Router(); -healthRouter.get("/", (_req, res) => { - const pool = getPoolStats(); - res.json({ - status: "ok", +healthRouter.get("/", async (_req, res) => { + const poolStats = getPoolStats(); + let databaseStatus: any; + 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", + database: databaseStatus, 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), + size: poolStats.poolSize, + active: poolStats.totalPages - poolStats.availablePages, + available: poolStats.availablePages, + queueDepth: poolStats.queueDepth, + pdfCount: poolStats.pdfCount, + restarting: poolStats.restarting, + uptimeSeconds: Math.round(poolStats.uptimeMs / 1000), }, - }); -}); + }; + + res.status(httpStatus).json(response); +}); \ No newline at end of file diff --git a/src/routes/health.ts.backup b/src/routes/health.ts.backup new file mode 100644 index 0000000..bbee73a --- /dev/null +++ b/src/routes/health.ts.backup @@ -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), + }, + }); +});