Add a switch to turn job dispatch off, and use it in the dev stack
The scheduler sends a queued job to any idle claimed printer in any farm. The dashboard dev stack is wired to the real printers, so testing the job upload UI there would have started a real print on the first idle one. DISPATCH_ENABLED=false (exactly that string) disables the timer and the nudge from POST /jobs; any other value that looks like an attempt to disable it is warned about, because a typo that silently leaves it on is the dangerous direction. scripts/e2e-camera.sh now always runs the backend with it off.
This commit is contained in:
@@ -4,6 +4,7 @@ import { printers, printJobs } from "../db/schema";
|
||||
import { getDownloadUrl, headObject } from "../s3";
|
||||
import { isGatewayOnline, sendPrinterCommand } from "../routes/ws/edge";
|
||||
import { nextJobStatus } from "./job_status";
|
||||
import { dispatchEnabled, dispatchSwitchWarning } from "./enabled";
|
||||
|
||||
/**
|
||||
* The job scheduler: picks up `queued` jobs and puts them on idle printers.
|
||||
@@ -152,6 +153,8 @@ async function releaseJob(jobId: string, outcome: "requeue" | "fail", reason: st
|
||||
export { nextJobStatus } from "./job_status";
|
||||
|
||||
export async function dispatchTick(): Promise<number> {
|
||||
// Also covers the nudge from `POST /jobs`, which calls this directly.
|
||||
if (!dispatchEnabled()) return 0;
|
||||
await reapStalledUploads();
|
||||
|
||||
let dispatched = 0;
|
||||
@@ -286,6 +289,12 @@ let timer: ReturnType<typeof setInterval> | undefined;
|
||||
/** Starts the scheduler. Idempotent, so a second call does not double-tick. */
|
||||
export function startDispatcher() {
|
||||
if (timer) return;
|
||||
const warning = dispatchSwitchWarning();
|
||||
if (warning) console.warn(`[dispatch] ${warning}`);
|
||||
if (!dispatchEnabled()) {
|
||||
console.log("[dispatch] DISABLED (DISPATCH_ENABLED=false): queued jobs will not be sent to printers");
|
||||
return;
|
||||
}
|
||||
timer = setInterval(() => {
|
||||
dispatchTick().catch((err) => console.error("[dispatch] tick failed", err));
|
||||
}, TICK_MS);
|
||||
|
||||
Reference in New Issue
Block a user