import type { Logger } from "webappwiz/log"; import type { Fs } from "../fs/fs.js"; import type { Lock } from "../lock/lock.js"; import type { Ps } from "../ps/ps.js"; /** * A machine's heavy-job slots: `take` one before a test run or an install, * and dispose of it after; `read` says who holds them and who waits. A holder * that dies gives its slot back by dying. Every process that opens the same * file shares one cap, whichever tool it runs in. */ export declare class HeavyJobs implements HeavyCap { #private; /** * The slots kept in `dir`, as `heavy.json` beside the `heavy.lock` that * guards it. */ static under(dir: string, { fs, ps, log, cap, held, }: Pick & { fs: Fs; ps: Ps; }): HeavyJobs; constructor( /** The file the slots are kept in, or a test's own. */ path: string, opts: HeavyJobsOptions); take({ what, task, }: { what: string; task?: string | null; }): Promise; read(): Promise; } /** A job that holds, or waits for, one of the machine's slots. */ export interface HeavyJob { /** What it runs, as a waiter names it: "preMerge", "bun test". */ what: string; /** The task it runs for, or null outside one. */ task: string | null; /** The process that holds the slot, which frees it by exiting. */ pid: number; /** When it started holding, or waiting. */ since: string; } /** Who holds the machine's slots, and who waits for one, first come first. */ export interface HeavyJobsReading { cap: number; running: HeavyJob[]; waiting: HeavyJob[]; } /** A slot taken, which its holder gives back when the job is done. */ export interface HeavySlot extends AsyncDisposable { /** * What to add to the environment of what runs in it, so a heavy job it * starts runs in this slot rather than waiting for another. */ readonly env: Record; } /** * Caps the heavy jobs (test runs, installs, browser launches) running at * once, so several agents testing together queue rather than pinning the CPU * and running out of memory. */ export interface HeavyCap { /** Waits for a free slot, saying what holds them all while it waits. */ take(job: { what: string; task?: string | null; }): Promise; read(): Promise; } export interface HeavyJobsOptions { fs: Fs; /** Tells a holder that died from one still running, and whose job this is. */ ps: Pick; /** Held while the file is read and rewritten, never while a job runs. */ lock: Lock; log: Logger; /** How many jobs run at once. */ cap: number; /** * The environment variable a slot sets for what runs in it; a job that * finds it set already runs in its parent's slot, and takes none. */ held: string; /** The current time; a test passes its own. */ now?: () => Date; }