Skip to content

Commit bc957f8

Browse files
committed
feat: add /readyz readiness probe with database check
1 parent 88884cb commit bc957f8

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/routes/readyz/+server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { json } from '@sveltejs/kit';
2+
import { sql } from 'drizzle-orm';
3+
import { db } from '$lib/server/db';
4+
import type { RequestHandler } from './$types';
5+
6+
// Readiness probe: reports 200 only when the app can actually serve traffic
7+
// (i.e. the database is reachable). This is distinct from /health, which is a
8+
// pure liveness check. Orchestrator readiness gates should point here; the
9+
// container liveness HEALTHCHECK stays on /health.
10+
export const GET: RequestHandler = async () => {
11+
try {
12+
await db.execute(sql`select 1`);
13+
} catch (err) {
14+
console.error('[readyz] database check failed', err);
15+
return json({ status: 'unavailable', checks: { database: 'down' } }, { status: 503 });
16+
}
17+
18+
return json({ status: 'ready', checks: { database: 'ok' } });
19+
};

tests/e2e/readyz.e2e.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('readiness endpoint reports ready when the database is reachable', async ({ request }) => {
4+
const response = await request.get('/readyz');
5+
expect(response.status()).toBe(200);
6+
const body = await response.json();
7+
expect(body.status).toBe('ready');
8+
expect(body.checks.database).toBe('ok');
9+
});

0 commit comments

Comments
 (0)