import { BatchClusterEmitter } from "./BatchClusterEmitter"; import { BatchProcess } from "./BatchProcess"; import { CombinedBatchProcessOptions } from "./CombinedBatchProcessOptions"; import { Task } from "./Task"; /** * Manages the lifecycle of a pool of BatchProcess instances. * Handles spawning, health monitoring, and cleanup of child processes. */ export declare class ProcessPoolManager { #private; private readonly options; private readonly emitter; private readonly onIdle; constructor(options: CombinedBatchProcessOptions, emitter: BatchClusterEmitter, onIdle: () => void); /** * Get all current processes */ get processes(): readonly BatchProcess[]; /** * Get the current number of spawned child processes */ get procCount(): number; /** * Alias for procCount to match BatchCluster interface */ get processCount(): number; /** * Get the current number of child processes currently servicing tasks */ get busyProcCount(): number; /** * Get the current number of starting processes */ get startingProcCount(): number; /** * Get the current number of ready processes */ get readyProcCount(): number; /** * Get the total number of child processes created by this instance */ get spawnedProcCount(): number; /** * Get the milliseconds until the next spawn is allowed */ get msBeforeNextSpawn(): number; /** * Get all currently running tasks from all processes */ currentTasks(): Task[]; /** * Find the first ready process that can handle a new task */ findReadyProcess(): BatchProcess | undefined; /** * @return the PIDs of every child this pool spawned whose "exit" event we * haven't seen yet, **including** children that have already left the pool * (because they're being recycled) and children that never made it into the * pool (because adoption failed). * * Contrast with {@link ProcessPoolManager.pids}, which reports only the * still-running members of the schedulable pool. This is what must be killed * if the host process exits mid-shutdown. */ unexitedPids(): number[]; /** * Verify that each BatchProcess PID is actually alive. * @return the spawned PIDs that are still in the process table. */ pids(): number[]; /** * @return true if {@link ProcessPoolManager.end} has been called. */ get ended(): boolean; /** * Permanently shut this pool down: no further child processes will be * spawned, and wait for every child this pool created to be terminated. * * By default this is a true barrier, so `await end(); process.exit(0)` cannot * orphan a child hidden inside an async `processFactory()`. The automatic * `beforeExit` path supplies `maxWaitMillis`, because Node cannot wait * forever for an opaque factory during process exit. If that bound expires, * shutdown force-kills everything currently visible and any factory result * that arrives while the host remains alive is still terminated. * * Draining `#procs` is not enough on its own: a `processFactory()` still in * flight can hand us a live child afterwards, and a process that * `vacuumProcs()` already removed from `#procs` can still be in its * graceful-shutdown window. * * Contrast with {@link ProcessPoolManager.closeChildProcesses}, which only * recycles the current children and leaves the pool able to spawn more. * * Rejects if a child this pool spawned is still running once termination * has finished. * * @param maxWaitMillis optional bound used only by automatic process-exit * cleanup. Omit it for the public `BatchCluster.end()` barrier. */ end(gracefully?: boolean, maxWaitMillis?: number): Promise; /** * Shut down any currently-running child processes. */ closeChildProcesses(gracefully?: boolean): Promise; /** * Run maintenance on currently spawned child processes. * Removes unhealthy processes and enforces maxProcs limit. */ vacuumProcs(): Promise; /** * Spawn new processes if needed based on pending task count and capacity */ maybeSpawnProcs(pendingTaskCount: number): Promise; /** * Update the maximum number of processes allowed */ setMaxProcs(maxProcs: number): void; }