SPB Git

Repository Public

worker.ts 1022 B 19 lines typescript

1/**2 * pnpm worker — the media worker (a second process next to the web server).3 * Stops cleanly on SIGINT/SIGTERM: the job in progress is given back to the queue without losing an attempt.4 * `pnpm worker --once` drains the queue and exits (used by tests and for one-shot runs).5 */6import { closeDb, db } from "../src/server/db";7import { log } from "../src/server/log";8import { ffmpegStatus } from "../src/server/transcode";9import { runWorker } from "../src/server/worker";1011const stop = new AbortController();12for (const sig of ["SIGINT", "SIGTERM"] as const) process.on(sig, () => { log("info", "worker.signal", { signal: sig }); stop.abort(); });1314db(); // creates or upgrades the database before the first claim15const tools = await ffmpegStatus(true);16if (!tools.ok) log("warn", "worker.ffmpeg_unavailable", { message: tools.message }); // it keeps running: the heartbeat and the dashboard say why nothing is encoded17await runWorker({ drain: process.argv.includes("--once"), signal: stop.signal });18closeDb();19
Files main
Menu

Theme