Files
netfelix-audio-fix/src/features/pipeline/PipelinePage.tsx
Felix Förtsch 23dca8bf0b
Some checks failed
Build and Push Docker Image / build (push) Failing after 8s
split scheduling into scan + process windows, move controls to settings page
the old one-window scheduler gated only the job queue. now the scan loop and
the processing queue have independent windows — useful when the container
runs as an always-on service and we only want to hammer jellyfin + ffmpeg
at night.

config keys renamed from schedule_* to scan_schedule_* / process_schedule_*,
plus the existing job_sleep_seconds. scheduler.ts exposes parallel helpers
(isInScanWindow / isInProcessWindow, waitForScanWindow / waitForProcessWindow)
so each caller picks its window without cross-contamination.

scan.ts checks the scan window between items and emits paused/resumed sse.
execute.ts keeps its per-job pause + sleep-between-jobs but now on the
process window. /api/execute/scheduler moved to /api/settings/schedule.

frontend: ScheduleControls popup deleted from the pipeline header, replaced
with a plain Start queue button. settings page grows a Schedule section with
both windows and the job sleep input.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:50:25 +02:00

110 lines
3.5 KiB
TypeScript

import { useCallback, useEffect, useRef, useState } from "react";
import { Button } from "~/shared/components/ui/button";
import { api } from "~/shared/lib/api";
import { DoneColumn } from "./DoneColumn";
import { ProcessingColumn } from "./ProcessingColumn";
import { QueueColumn } from "./QueueColumn";
import { ReviewColumn } from "./ReviewColumn";
interface PipelineData {
review: any[];
reviewTotal: number;
queued: any[];
processing: any[];
done: any[];
doneCount: number;
jellyfinUrl: string;
}
interface Progress {
id: number;
seconds: number;
total: number;
}
interface QueueStatus {
status: string;
until?: string;
seconds?: number;
}
export function PipelinePage() {
const [data, setData] = useState<PipelineData | null>(null);
const [progress, setProgress] = useState<Progress | null>(null);
const [queueStatus, setQueueStatus] = useState<QueueStatus | null>(null);
const [loading, setLoading] = useState(true);
const load = useCallback(async () => {
const pipelineRes = await api.get<PipelineData>("/api/review/pipeline");
setData(pipelineRes);
setLoading(false);
}, []);
const startQueue = useCallback(async () => {
await api.post("/api/execute/start");
load();
}, [load]);
useEffect(() => {
load();
}, [load]);
// SSE for live updates. job_update fires on every status change and per-line
// stdout flush of the running job — without coalescing, the pipeline endpoint
// (a 500-row review query + counts) would re-run several times per second.
const reloadTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => {
const scheduleReload = () => {
if (reloadTimer.current) return;
reloadTimer.current = setTimeout(() => {
reloadTimer.current = null;
load();
}, 1000);
};
const es = new EventSource("/api/execute/events");
es.addEventListener("job_update", (e) => {
// When a job leaves 'running' (done / error / cancelled), drop any
// stale progress so the bar doesn't linger on the next job's card.
try {
const upd = JSON.parse((e as MessageEvent).data) as { id: number; status: string };
if (upd.status !== "running") setProgress(null);
} catch {
/* ignore malformed events */
}
scheduleReload();
});
es.addEventListener("job_progress", (e) => {
setProgress(JSON.parse((e as MessageEvent).data));
});
es.addEventListener("queue_status", (e) => {
setQueueStatus(JSON.parse((e as MessageEvent).data));
});
return () => {
es.close();
if (reloadTimer.current) clearTimeout(reloadTimer.current);
};
}, [load]);
if (loading || !data) return <div className="p-6 text-gray-500">Loading pipeline...</div>;
return (
<div className="flex flex-col -mx-3 sm:-mx-5 -mt-4 -mb-12 h-[calc(100vh-3rem)] overflow-hidden">
<div className="flex items-center justify-between px-6 py-3 border-b shrink-0">
<h1 className="text-lg font-semibold">Pipeline</h1>
<div className="flex items-center gap-4">
<span className="text-sm text-gray-500">{data.doneCount} files in desired state</span>
<Button variant="primary" size="sm" onClick={startQueue}>
Start queue
</Button>
</div>
</div>
<div className="flex flex-1 gap-4 p-4 overflow-x-auto overflow-y-hidden min-h-0">
<ReviewColumn items={data.review} total={data.reviewTotal} jellyfinUrl={data.jellyfinUrl} onMutate={load} />
<QueueColumn items={data.queued} onMutate={load} />
<ProcessingColumn items={data.processing} progress={progress} queueStatus={queueStatus} onMutate={load} />
<DoneColumn items={data.done} onMutate={load} />
</div>
</div>
);
}