Milestone (c): worker and downloads with live progress
- Worker queue with per-model exclusivity and MAX_CONCURRENT_DOWNLOADS, spawns `hf download --revision <sha> --local-dir ... --include <exact paths>` with HF_TOKEN via env only - Progress from bytes on disk (final + .incomplete files matched by etag), per job and per file, with speed and ETA; post-download size/etag check - Job logs (sanitized), cancel, graceful interrupt on shutdown, partial-file cleanup (hf 2.1.1 does not resume partials) - Single-worker DB lease, free-space check - SSE live updates for library, model and job pages - Dockerfile + compose.yaml (web, worker, data/models volumes) - HF_HUB_DISABLE_XET default on for measurable progress Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f7ac60ccf
commit
49440154a2
42 files changed
+2974
-110
No files matched your search
@@ -0,0 +1,148 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { cancelJob } from "@/components/job-actions";
|
||||
import { JobFilesTable } from "@/components/job-files-table";
|
||||
import { JobProgress } from "@/components/job-progress";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import { formatDuration } from "@/lib/format";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import type { JobSnapshot } from "@/lib/jobs";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
export function JobLive({ initial }: { initial: JobSnapshot }) {
|
||||
const { snapshot, logs } = useLive({ job: initial.id }, true);
|
||||
const job = snapshot?.jobs[0] ?? initial;
|
||||
const files = snapshot?.files ?? [];
|
||||
const open = OPEN.includes(job.state);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const logRef = useRef<HTMLDivElement>(null);
|
||||
const [follow, setFollow] = useState(true);
|
||||
useEffect(() => {
|
||||
if (follow && logRef.current) logRef.current.scrollTop = logRef.current.scrollHeight;
|
||||
}, [logs, follow]);
|
||||
|
||||
// Tick once per second while running so the duration keeps counting.
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
useEffect(() => {
|
||||
if (job.finishedAt != null) return;
|
||||
const t = setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => clearInterval(t);
|
||||
}, [job.finishedAt]);
|
||||
const duration = job.startedAt != null ? ((job.finishedAt ?? now) - job.startedAt) / 1000 : null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h1 className="text-xl font-semibold">
|
||||
{job.kind === "download" ? "Download" : job.kind} ·{" "}
|
||||
<Link href={`/models/${job.modelId}`} className="hover:underline">
|
||||
{job.repoId}
|
||||
</Link>
|
||||
</h1>
|
||||
{open && (
|
||||
<Button
|
||||
className="ml-auto"
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={busy || job.cancelRequested}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
await cancelJob(job.id);
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
{job.cancelRequested ? "Cancelling…" : "Cancel"}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<JobProgress job={job} />
|
||||
<dl className="grid grid-cols-[max-content_1fr] gap-x-6 gap-y-1 text-sm">
|
||||
<dt className="text-muted-foreground">Created</dt>
|
||||
<dd><LocalTime value={job.createdAt} /></dd>
|
||||
<dt className="text-muted-foreground">Started</dt>
|
||||
<dd>
|
||||
<LocalTime value={job.startedAt} />
|
||||
{job.attempt > 1 ? ` (attempt ${job.attempt})` : ""}
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Finished</dt>
|
||||
<dd><LocalTime value={job.finishedAt} /></dd>
|
||||
<dt className="text-muted-foreground">Duration</dt>
|
||||
<dd>{formatDuration(duration)}</dd>
|
||||
{job.exitCode != null && (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Exit code</dt>
|
||||
<dd className="font-mono">{job.exitCode}</dd>
|
||||
</>
|
||||
)}
|
||||
</dl>
|
||||
{job.errorMessage && (
|
||||
<pre className="rounded-md bg-destructive/10 px-3 py-2 text-xs whitespace-pre-wrap text-destructive">
|
||||
{job.errorMessage}
|
||||
</pre>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{files.length > 0 && (
|
||||
<Card className="py-0">
|
||||
<CardHeader className="pt-4">
|
||||
<CardTitle>Files</CardTitle>
|
||||
</CardHeader>
|
||||
<JobFilesTable files={files} />
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card className="gap-2">
|
||||
<CardHeader className="flex flex-row items-center justify-between">
|
||||
<CardTitle>Log</CardTitle>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<label className="flex items-center gap-1.5 text-muted-foreground">
|
||||
<input type="checkbox" checked={follow} onChange={(e) => setFollow(e.target.checked)} />
|
||||
Follow
|
||||
</label>
|
||||
<a href={`/api/jobs/${job.id}/log`} className="underline">
|
||||
Download full log
|
||||
</a>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div
|
||||
ref={logRef}
|
||||
className="h-96 overflow-auto rounded-md bg-muted/50 p-3 font-mono text-xs leading-relaxed"
|
||||
>
|
||||
{logs.length === 0 ? (
|
||||
<span className="text-muted-foreground">No output yet.</span>
|
||||
) : (
|
||||
logs.map((l) => (
|
||||
<div
|
||||
key={l.id}
|
||||
className={
|
||||
l.stream === "stderr"
|
||||
? "text-amber-700 dark:text-amber-400"
|
||||
: l.stream === "system"
|
||||
? "text-sky-700 dark:text-sky-400"
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<span className="text-muted-foreground select-none">
|
||||
{new Date(l.ts).toLocaleTimeString("en-GB")}{" "}
|
||||
</span>
|
||||
<span className="whitespace-pre-wrap break-all">{l.line}</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { getJob } from "@/lib/jobs";
|
||||
import { JobLive } from "./job-live";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function JobPage({ params }: PageProps<"/jobs/[id]">) {
|
||||
const { id } = await params;
|
||||
const job = await getJob(id);
|
||||
if (!job) notFound();
|
||||
return <JobLive initial={job} />;
|
||||
}
|
||||
Reference in new issue
Block a user