feat(health): service_status cache table + repo
This commit is contained in:
14
lib/db/repos/service_status.js
Normal file
14
lib/db/repos/service_status.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { pool } from '../pool.js';
|
||||
export async function upsert({ service_id, status, latency_ms = null, detail = null }) {
|
||||
await pool.query(
|
||||
`INSERT INTO service_status (service_id, status, latency_ms, detail, checked_at)
|
||||
VALUES ($1,$2,$3,$4, now())
|
||||
ON CONFLICT (service_id) DO UPDATE
|
||||
SET status=EXCLUDED.status, latency_ms=EXCLUDED.latency_ms,
|
||||
detail=EXCLUDED.detail, checked_at=now()`,
|
||||
[service_id, status, latency_ms, detail]);
|
||||
}
|
||||
export async function all() {
|
||||
const { rows } = await pool.query(`SELECT * FROM service_status`);
|
||||
return rows;
|
||||
}
|
||||
Reference in New Issue
Block a user