import { BatchClusterEmitter } from "./BatchClusterEmitter"; import { Logger } from "./Logger"; export declare const secondMs = 1000; export declare const minuteMs: number; /** * These parameter values have somewhat sensible defaults, but can be * overridden for a given BatchCluster. */ export declare class BatchClusterOptions { /** * No more than `maxProcs` child processes will be run at a given time * to serve pending tasks. A child keeps its slot until it exits. * * Defaults to 1. */ maxProcs: number; /** * Child processes will be recycled when they reach this age. A child that * reaches this age while running a task will finish that task before being * recycled. * * If non-zero, this value must not be less than `spawnTimeoutMillis`. * * Defaults to 5 minutes. Set to 0 to disable. */ maxProcAgeMillis: number; /** * This is the minimum interval between calls to BatchCluster's #onIdle * method, which runs general janitorial processes like child process * management and task queue validation. * * Must be > 0. Defaults to 10 seconds. */ onIdleIntervalMillis: number; /** * Spawning new child processes and servicing a "version" task must not take * longer than `spawnTimeoutMillis` before the process is considered failed, * and need to be restarted. Be pessimistic here--windows can regularly take * several seconds to spin up a process, thanks to antivirus shenanigans. * * Defaults to 15 seconds. Set to 0 to disable. */ spawnTimeoutMillis: number; /** * If maxProcs > 1, spawning new child processes to process tasks can slow * down initial processing, and create unnecessary processes. * * Must be >= 0ms. Defaults to 1.5 seconds. */ minDelayBetweenSpawnMillis: number; /** * If commands take longer than this, presume the underlying process is dead * and we should fail the task with a `TaskTimeoutError`. The timeout starts * when a process begins the task, and `Task.resetTimeout()` restarts it. If * the parent's event loop was blocked past the deadline, the task waits * while the child's output is still arriving (more is read within * `streamFlushMillis` of the previous check, or batch-cluster is still * handling output it read), for at most as long as the block overran the * deadline. * * This should be set to something on the order of seconds to a minute, but at * least 2-10 times longer than the expected task duration under typical load. * * You don't want this set too low, or tasks may be marked as failed * unnecessarily! * * Defaults to 0 (disabled). */ taskTimeoutMillis: number; /** * Processes will be recycled after processing `maxTasksPerProcess` tasks. * Depending on the commands and platform, batch mode commands shouldn't * exhibit unduly memory leaks for at least tens if not hundreds of tasks. * Setting this to a low number (like less than 10) will impact performance * markedly, due to OS process start/stop maintenance. Setting this to a very * high number (> 1000) may result in more memory being consumed than * necessary. * * Must be >= 0. Defaults to 500 */ maxTasksPerProcess: number; /** * When `this.end()` is called, or Node broadcasts the `beforeExit` event, * this is the milliseconds spent waiting for currently running tasks to * finish before sending kill signals to child processes. * * Setting this value to 0 means child processes will immediately receive a * kill signal to shut down. Any pending requests may be interrupted. Must be * >= 0. Defaults to 500ms. */ endGracefulWaitTimeMillis: number; /** * When a task's pass/fail token is detected on one stream (stdout or * stderr), this is how long to wait for the *other* stream to flush before * running the parser. * * Since stdout is typically line-buffered, it may arrive after stderr, so * this value needs to be large enough for the OS to flush stdout. * * Note that this puts a hard lower limit on task latency for tasks whose * token is found on stderr. If you set this too low, tasks may be * erroneously resolved or rejected, and you'll see `noTaskData` events. * * Setting this to 0 will most likely result in internal errors (due to * stream buffers not being associated to tasks that were just settled). */ streamFlushMillis: number; /** * Should batch-cluster try to clean up after spawned processes that don't * shut down? * * Only disable this if you have another means of PID cleanup. * `BatchProcess.end()` still rejects if that child is running 5 seconds * after termination. * * Defaults to `true`. */ cleanupChildProcs: boolean; /** * If a child process is idle for more than this value (in milliseconds), shut * it down to reduce system resource consumption. * * A value of ~10 seconds to a couple minutes would be reasonable. Set this to * 0 to disable this feature. */ maxIdleMsPerProcess: number; /** * How many failed tasks should a process be allowed to process before it is * recycled? * * Defaults to 0 (disabled), because a rejected task usually means bad input * rather than a sick child, and this counts failures over the process's * whole lifetime rather than consecutive ones: a long-lived child would be * recycled after any two bad inputs, ever. * * Set this if a task failure is a reliable signal that the child itself is * unhealthy. Consider `healthCheckCommand` instead if you can ask the child * directly. */ maxFailedTasksPerProcess: number; /** * Should termination signal the child's entire process group, rather than * just the child? * * Enable this if your `processFactory` spawns children with `detached: true`, * which makes each child the leader of its own process group: it lets us also * stop any grandchildren the child spawned, which would otherwise survive * even when their direct parent exits gracefully. * * Harmless for non-detached children -- signalling a group that doesn't exist * fails, and we then signal the child directly -- but pointless, as their * descendants aren't in a group we can name. * * Windows has no POSIX process groups, so this is ignored there. */ killProcessGroup: boolean; /** * If `healthCheckCommand` is set, how frequently should we check for * unhealthy child processes? * * Set this to 0 to disable this feature. */ healthCheckIntervalMillis: number; /** * Verify child processes are still running by checking the OS process table. * * Set this to 0 to disable this feature. */ pidCheckIntervalMillis: number; /** * When true, child process streams (stdin, stdout, stderr) are unreferenced * so they don't prevent the parent Node.js process from exiting naturally. * * This allows scripts to exit without explicitly calling `.end()` on the * BatchCluster instance. The child processes will be cleaned up automatically * when the parent process exits. * * Set to `false` if you need the parent process to stay alive as long as * child processes are running (legacy behavior prior to v17). * * Defaults to `true`. * * @since 17.0.0 */ unrefStreams: boolean; /** * A BatchCluster instance and associated BatchProcess instances will share * this `Logger`. Defaults to the `Logger` instance provided to `setLogger()`. */ logger: () => Logger; /** * When true, BatchCluster registers `process.on("beforeExit")` and * `process.on("exit")` handlers to clean up child processes when the Node.js * process exits. * * The `beforeExit` handler calls `end(true)` for graceful shutdown. * The `exit` handler synchronously kills any remaining child processes. * * Set to `false` if you want to manage process cleanup yourself, or if you're * experiencing issues with these handlers interfering with your application's * exit behavior. * * Defaults to `true`. * * @since 17.1.0 */ cleanupChildProcsOnExit: boolean; } export interface WithObserver { observer: BatchClusterEmitter; }