batch-cluster
    Preparing search index...

    Class BatchCluster

    BatchCluster instances manage 0 or more homogeneous child processes, and provide the main interface for enqueuing Tasks via enqueueTask.

    Given the large number of configuration options, the constructor receives a single options hash. The most important of these are the ChildProcessFactory, which specifies the factory that creates ChildProcess instances, and BatchProcessOptions, which specifies how child tasks can be verified and shut down.

    Index

    Constructors

    Properties

    emitter: BatchClusterEmitter = ...
    off: <E extends keyof BatchClusterEvents>(
        eventName: E,
        listener: (...args: Args<BatchClusterEvents[E]>) => void,
    ) => this = ...

    BatchClusterEvents

    v9.0.0

    on: <E extends keyof BatchClusterEvents>(
        eventName: E,
        listener: (...args: Args<BatchClusterEvents[E]>) => void,
    ) => this = ...

    BatchClusterEvents

    Accessors

    • get busyProcCount(): number

      Returns number

      the current number of child processes currently servicing tasks

    • get isIdle(): boolean

      Returns boolean

      true if all previously-enqueued tasks have settled

    • get meanTasksPerProc(): number

      Returns number

      the mean number of tasks completed by child processes

    • get pendingTasks(): readonly Task<unknown>[]

      Returns readonly Task<unknown>[]

      the current pending Tasks (mostly for testing)

    • get procCount(): number

      Returns number

      the current number of spawned child processes. Some (or all) may be idle.

    • get spawnedProcCount(): number

      Returns number

      the total number of child processes created by this instance

    Methods

    • Shut down any currently-running child processes. New child processes will be started automatically to handle new tasks.

      Parameters

      • gracefully: boolean = true

      Returns Promise<void>

    • Shut down this instance, and all child processes.

      Parameters

      • gracefully: boolean = true

        should an attempt be made to finish in-flight tasks, or should we force-kill child PIDs.

      Returns Deferred<void>

    • Submits task for processing by a BatchProcess instance

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

      a Promise that is resolved or rejected once the task has been attempted on an idle BatchProcess

    • Verify that each BatchProcess PID is actually alive.

      Returns number[]

      the spawned PIDs that are still in the process table.

    • Reset the maximum number of active child processes to maxProcs. Note that this is handled gracefully: child processes are only reduced as tasks are completed.

      Parameters

      • maxProcs: number

      Returns void

    • Run maintenance on currently spawned child processes. This method is normally invoked automatically as tasks are enqueued and processed.

      Only public for tests.

      Returns Promise<void[]>