SPB Git

Repository Public

run-job.ts 1.8 KB 25 lines typescript

1// Run one job in the foreground: tsx scripts/run-job.ts sync|epg|check [n]2import { closeDb, getNum, bumpCatalog } from "@/server/db";3import { dueStreams, runBatch } from "@/server/checker";4import { refreshEpg } from "@/server/epg";5import { syncCatalog } from "@/server/sync";6import { importVod } from "@/server/vod";7import { scanLibrary } from "@/server/library";89const [kind, arg] = process.argv.slice(2);10const main = async () => {11  if (kind === "sync") console.log(JSON.stringify(await syncCatalog(), null, 1));12  else if (kind === "epg") console.log(JSON.stringify(await refreshEpg(), null, 1));13  else if (kind === "vod") console.log(JSON.stringify(await importVod(), null, 1));14  else if (kind === "sources") { const { refreshSources } = await import("@/server/engine"); console.log(JSON.stringify(await refreshSources(), null, 1)); }15  else if (kind === "tmdb") { const { enrichTmdb } = await import("@/server/tmdb"); console.log(JSON.stringify(await enrichTmdb(Number(arg ?? 6000)), null, 1)); }16  else if (kind === "onf") { const { importOnf } = await import("@/server/onf"); console.log(JSON.stringify(await importOnf(Number(arg ?? 20)), null, 1)); }17  else if (kind === "library") console.log(JSON.stringify(await scanLibrary(), null, 1));18  else if (kind === "check") {19    const batch = dueStreams(Number(arg ?? 100));20    const r = await runBatch(batch, { concurrency: getNum("check_concurrency"), hostDelayMs: getNum("check_host_delay_ms"), timeoutMs: getNum("check_timeout_ms"), onResult: (s, p) => console.log(p.status.padEnd(5), String(p.httpStatus ?? "-").padEnd(4), p.cors ? "cors" : "    ", s.url.slice(0, 90), p.error ?? "") });21    bumpCatalog(); console.log(r);22  } else { console.error("usage: run-job.ts sync|epg|vod|library|check [n]"); process.exit(2); }23};24main().then(() => { closeDb(); process.exit(0); }, (e) => { console.error(e); process.exit(1); });25
Files main
Menu

Theme