import { realpath } from "node:fs/promises"; import { readHeavyQueue } from "yt-dlp-transcript-common/lib/heavyQueue.mjs"; import { heavyLockFile, renderPriorityFile } from "yt-dlp-transcript-common/lib/renderPriority.mjs"; import { REPO_ROOT } from "@/lib/paths.mjs"; import { projectRef } from "@/lib/projects"; import { projectEtas } from "@/lib/report/takeEta.mjs"; export const dynamic = "force-dynamic"; // THE RENDER QUEUE (UI notes 2026-10-30, #18), for the take panel: what runs // in the machine's heavy slot and what waits at it, and for what -- read from // the slot's own files beside its lock (common/lib/heavyQueue.mjs: // heavy-queue.lock.jobs/, .waiting/, the line's and the build slot's holders, // the e2e suites' queues, render mode), never guessed -- and, with a project, // how long a take of it renders, from its past renders (lib/report/takeEta.mjs). // Read only: render mode is turned on by "Give renders the machine" (a take's // --priority) or `umtool render-mode on`. // // GET ?project= -> { queue, etas, mine } `mine`: the running and waiting renders of this project const noStore = { "cache-control": "no-store" }; export async function GET(request: Request) { const url = new URL(request.url); const queue = readHeavyQueue({ heavyLock: heavyLockFile(process.env, { root: REPO_ROOT }), renderFile: renderPriorityFile(process.env, { root: REPO_ROOT }), }); const id = url.searchParams.get("project"); const project = id ? await projectRef(id) : null; if (!project) return Response.json({ queue, etas: null, mine: [] }, { headers: noStore }); const dir = await realpath(project.dir).catch(() => project.dir); const same = async (d: string | undefined) => !!d && ((await realpath(d).catch(() => d)) === dir || d === project.dir); const mine: { pid: number; take: string | null; state: "running" | "waiting"; forSeconds: number | null; stage?: string }[] = []; for (const r of queue.running) if (r.kind === "render" && (await same(r.projectDir))) mine.push({ pid: r.pid, take: r.take ?? null, state: "running", forSeconds: r.forSeconds }); for (const w of queue.waiting) if (w.kind === "render" && (await same(w.projectDir))) mine.push({ pid: w.pid, take: w.take ?? null, state: "waiting", forSeconds: w.forSeconds, stage: w.stageWords }); return Response.json({ queue, etas: await projectEtas(project.dir), mine }, { headers: noStore }); }