feat: real worker status, covers on Recently Pressed, library counter

- Worker stamps a throttled worker.heartbeat; GET /api/worker reports online
  from its updatedAt recency (DB-time); masthead shows a live listening/offline
  dot instead of a static decoration.
- /api/requests enriched with rgMbid; Recently Pressed shows cover thumbs.
- Library album count moved from the filter row into a section header.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-12 17:58:23 +02:00
parent e624d12089
commit 606ea82b70
10 changed files with 103 additions and 15 deletions
+6 -4
View File
@@ -35,10 +35,11 @@ export async function POST(request: Request) {
}
export async function GET() {
const requests = await prisma.request.findMany({
orderBy: { createdAt: "desc" },
include: { job: true },
});
const [requests, releases] = await Promise.all([
prisma.request.findMany({ orderBy: { createdAt: "desc" }, include: { job: true } }),
prisma.monitoredRelease.findMany({ select: { artistName: true, album: true, rgMbid: true } }),
]);
const rgByKey = new Map(releases.map((mr) => [`${mr.artistName} ${mr.album}`, mr.rgMbid]));
return Response.json({
requests: requests.map((r) => ({
@@ -47,6 +48,7 @@ export async function GET() {
album: r.album,
status: r.status,
createdAt: r.createdAt,
rgMbid: rgByKey.get(`${r.artist} ${r.album}`) ?? null,
job: r.job ? { state: r.job.state, currentStage: r.job.currentStage } : null,
})),
});
+24
View File
@@ -0,0 +1,24 @@
import { describe, it, expect } from "vitest";
import { prisma } from "@/lib/db";
import { GET } from "./route";
async function online() {
return (await (await GET()).json()).online;
}
describe("worker status API", () => {
it("reports offline when there is no heartbeat", async () => {
expect(await online()).toBe(false);
});
it("reports online for a fresh heartbeat", async () => {
await prisma.config.create({ data: { key: "worker.heartbeat", value: "1", secret: false } });
expect(await online()).toBe(true);
});
it("reports offline for a stale heartbeat", async () => {
await prisma.config.create({ data: { key: "worker.heartbeat", value: "1", secret: false } });
await prisma.$executeRaw`UPDATE "Config" SET "updatedAt" = now() - interval '5 minutes' WHERE key = 'worker.heartbeat'`;
expect(await online()).toBe(false);
});
});
+10
View File
@@ -0,0 +1,10 @@
import { prisma } from "@/lib/db";
// The worker stamps worker.heartbeat every ~15s; it's "online" if that row was updated
// recently. Uses DB time on both write and read so container clock skew doesn't matter.
export async function GET() {
const rows = await prisma.$queryRaw<{ online: boolean }[]>`
SELECT (now() - "updatedAt") < interval '40 seconds' AS online
FROM "Config" WHERE key = 'worker.heartbeat'`;
return Response.json({ online: rows[0]?.online ?? false });
}