import { kickQueue } from "@/lib/queue/runner"; import { cancelStep, isQid, retryStep } from "@/lib/queue/store.mjs"; import { queueDir } from "@/lib/queue/runner"; import { queueView } from "@/lib/queue/view"; import { walkStats } from "@/lib/projects/walk.mjs"; export const dynamic = "force-dynamic"; // THE DURABLE QUEUE (lib/queue/store.mjs), for /jobs and the Takes panel. // // GET [?project=][&all=1] { dir, runner, steps }: the runner (is the app // running the queue, and since when) and the // steps, newest first (not finished, or finished // in the last day; all=1 every one) // POST ?cancel= | ?retry= what `umtool queue cancel|retry` do // // Steps are ADDED from a terminal (`umtool queue add -- `), never here: // a step is a command line, and a page that took one would run whatever it was // sent. const noStore = { "cache-control": "no-store" }; export async function GET(request: Request) { const url = new URL(request.url); // `?walks=1`: how many project walks this process has started and how many run now (lib/projects/walk.mjs) -- the // load check's idle gauge (walk-load.spec.ts), read only. if (url.searchParams.get("walks") === "1") return Response.json({ walks: { ...walkStats } }, { headers: noStore }); const view = await queueView({ project: url.searchParams.get("project"), all: url.searchParams.get("all") === "1" }); return Response.json(view, { headers: noStore }); } export async function POST(request: Request) { const url = new URL(request.url); const cancel = url.searchParams.get("cancel"); const retry = url.searchParams.get("retry"); const qid = cancel ?? retry; if (!isQid(qid)) return Response.json({ error: "?cancel= or ?retry=" }, { status: 400 }); try { const r = cancel ? await cancelStep(queueDir(), qid, { by: "the umtool app (/jobs)" }) : await retryStep(queueDir(), qid); kickQueue(); return Response.json({ ok: true, said: r.said }, { headers: noStore }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 409 }); } }