Open History to see the last commit
1import { databasePool } from "@/lib/db";
2export const dynamic = "force-dynamic";
3export async function GET() {
4 try {
5 const { rows } = await databasePool()
6 .query(`SELECT s.state, s.checked_at, s.committed_at,
7 (l.active_until > now()) AS owned FROM ingest_status s CROSS JOIN ingest_leases l WHERE s.id = 1 AND l.id = 1`);
8 const status = rows[0];
9 const checkedAt = status?.checked_at
10 ? new Date(status.checked_at).toISOString()
11 : null;
12 const fresh =
13 checkedAt && Date.now() - Date.parse(checkedAt) < 30000 && status.owned;
14 return Response.json(
15 {
16 state: fresh ? status.state : "degraded",
17 checkedAt,
18 committedAt: status?.committed_at ?? null,
19 },
20 { headers: { "Cache-Control": "no-store" } },
21 );
22 } catch {
23 return Response.json(
24 { state: "degraded", checkedAt: null, committedAt: null },
25 { status: 503 },
26 );
27 }
28}