import type { ChildProcess, SpawnOptions } from 'child_process'; import type { Logger } from '../services/ports/logger.js'; import type { WorkerPool } from '../services/ports/workerPool.js'; export type SpawnFn = (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess; export interface NodeWorkerPoolOptions { /** The path of the compiled `worker/main.js`. */ script: string; /** `--max-old-space-size` of the worker (`workerMemoryMb`, § 8.7). */ memoryMb: number; logger: Logger; /** The Node binary; the one that runs this process by default. */ execPath?: string; /** The environment the worker starts with; this process's by default. */ env?: NodeJS.ProcessEnv; /** * The limits the worker's database connections get (S6): only the worker's * environment sets them, so that it fails fast and does not queue behind a * storefront lock. A limit that is not given is not set. */ databaseTimeouts?: { lockMs?: number; statementMs?: number; }; /** For a test. */ spawn?: SpawnFn; } /** * Starts the workers as Node processes (§ 8.4, the spawn contract): * * - `detached`, so a signal sent to the group of the event process does not * reach it, and `unref`, so the event process does not wait for it; * - no IPC channel and no input; the output of the worker goes where the output * of this process goes, as it does for the event and cron processes; * - the memory ceiling as an argument, and `ALLOW_CONFIG_MUTATIONS=true`, which * the bootstrap of the modules needs and the event process has switched off * after its own boot (`startSubscriberProcess` sets it for the same reason); * - the database limits of S6 (`DB_LOCK_TIMEOUT_MS`), read by `connection.ts` * when the worker loads it, which is why they are set here and not in `main`. * * It counts the workers it has started that have not ended, for the limit of * `maxWorkersPerInstance`. A worker of an earlier event process is not counted. */ export declare class NodeWorkerPool implements WorkerPool { private readonly options; private readonly live; constructor(options: NodeWorkerPoolOptions); running(): number; start(jobUuid: string): void; }