forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
37 lines (32 loc) · 1.04 KB
/
Copy pathroute.ts
File metadata and controls
37 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { NextResponse } from "next/server";
import { sql } from "drizzle-orm";
import { getDb } from "@/server/db";
import { pistonQueueStats, pistonRuntimes } from "@/lib/piston";
// Always run at request time — this checks live dependencies.
export const dynamic = "force-dynamic";
/**
* Stack health check: verifies the SQLite DB and the Piston sandbox are both
* reachable. Returns 200 only when the whole stack is up, 503 otherwise.
*/
export async function GET() {
const checks = { db: false, piston: false, runtimes: [] as string[] };
try {
const db = getDb();
await db.run(sql`select 1`);
checks.db = true;
} catch {
checks.db = false;
}
try {
const runtimes = await pistonRuntimes();
checks.piston = true;
checks.runtimes = runtimes.map((r) => `${r.language}@${r.version}`);
} catch {
checks.piston = false;
}
const ok = checks.db && checks.piston;
return NextResponse.json(
{ ok, ...checks, judgeQueue: pistonQueueStats(), at: new Date().toISOString() },
{ status: ok ? 200 : 503 },
);
}