// IS ANYTHING ABOUT TO WRITE THIS VIDEO'S SAVED COPY? (compaction's drop // guard, review H4.) A download, a persist, an attach or an import of the // same video that is queued or running may land a container on the pointer // while an original is being dropped — the drop then refuses, naming it. // // A job counts when it is of a kind that can persist a container, for this // channel, and either names this video (`videoId`, or `spec.params.ids`) or // names no video at all (a channel-wide run: it may reach this one). The // download lane's in-flight units (they make no job record) count by their // video id. The compaction job itself never counts. import { getRegistry } from "../jobs/registry"; import { getAutoRunnerStatus } from "./autoRunner"; export const VIDEO_WRITING_KINDS: ReadonlySet = new Set([ "auto-download-unit", "download-from-playlist", "download-missing", "download-missing-subs", "download-one-pipeline", "import-one", "import-archive-org", "redownload-archive", "redownload-incomplete-bucket", "retry-bucket", "sync", "persist-kept", "persist-videos", "fetch-windows", "attach-media", "import-media", "record-live", "import-local-media", ]); export function videoPersistBusyReason(slug: string, id: string): string | null { const jobs = getRegistry() .list() .filter((j) => { if (!VIDEO_WRITING_KINDS.has(j.kind)) return false; if (j.status !== "queued" && j.status !== "running") return false; if (j.channelSlug && j.channelSlug !== slug) return false; if (j.videoId) return j.videoId === id; const ids = (j.spec?.params as { ids?: unknown } | undefined)?.ids; if (Array.isArray(ids)) return ids.includes(id); return j.channelSlug === slug; }); if (jobs.length) { return `a ${jobs[0].kind} job (${jobs[0].status}, ${jobs[0].id}) may write this video's saved copy — wait for it to end`; } try { const unit = getAutoRunnerStatus("download").inFlight.find((u) => u.channelSlug === slug && u.videoId === id); if (unit) return "the download lane is downloading this video now — wait for it to end"; } catch { // No runner in this process (a CLI): nothing in flight here. } return null; }