Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/routes/readyz/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { json } from '@sveltejs/kit';
import { sql } from 'drizzle-orm';
import { db } from '$lib/server/db';
import type { RequestHandler } from './$types';

// Readiness probe: reports 200 only when the app can actually serve traffic
// (i.e. the database is reachable). This is distinct from /health, which is a
// pure liveness check. Orchestrator readiness gates should point here; the
// container liveness HEALTHCHECK stays on /health.
export const GET: RequestHandler = async () => {
try {
await db.execute(sql`select 1`);
} catch (err) {
console.error('[readyz] database check failed', err);
return json({ status: 'unavailable', checks: { database: 'down' } }, { status: 503 });
}

return json({ status: 'ready', checks: { database: 'ok' } });
Comment thread
dobby-coder[bot] marked this conversation as resolved.
Outdated
};
9 changes: 9 additions & 0 deletions tests/e2e/readyz.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from '@playwright/test';

test('readiness endpoint reports ready when the database is reachable', async ({ request }) => {
Comment thread
dobby-coder[bot] marked this conversation as resolved.
const response = await request.get('/readyz');
expect(response.status()).toBe(200);
const body = await response.json();
expect(body.status).toBe('ready');
expect(body.checks.database).toBe('ok');
});
Loading