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.

Constructors

Properties

emitter: BatchClusterEmitter = ...
off: (<E>(eventName, listener) => this) = ...

Type declaration

    • <E>(eventName, listener): this
    • Type Parameters

      Parameters

      • eventName: E
      • listener: ((...args) => void)

      Returns this

See

BatchClusterEvents

Since

v9.0.0

on: (<E>(eventName, listener) => this) = ...

Type declaration

    • <E>(eventName, listener): this
    • Type Parameters

      Parameters

      • eventName: E
      • listener: ((...args) => void)

      Returns this

See

BatchClusterEvents

options: AllOpts

Accessors

  • get busyProcCount(): number
  • Returns number

    the current number of child processes currently servicing tasks

  • get childEndCounts(): {
        broken: number;
        closed: number;
        ended: number;
        ending: number;
        idle: number;
        old: number;
        proc.close: number;
        proc.disconnect: number;
        proc.error: number;
        proc.exit: number;
        startError: number;
        stderr: number;
        stderr.error: number;
        stdin.error: number;
        stdout.error: number;
        timeout: number;
        tooMany: number;
        unhealthy: number;
        worn: number;
    }
  • Returns {
        broken: number;
        closed: number;
        ended: number;
        ending: number;
        idle: number;
        old: number;
        proc.close: number;
        proc.disconnect: number;
        proc.error: number;
        proc.exit: number;
        startError: number;
        stderr: number;
        stderr.error: number;
        stdin.error: number;
        stdout.error: number;
        timeout: number;
        tooMany: number;
        unhealthy: number;
        worn: number;
    }

    • broken: number
    • closed: number
    • ended: number
    • ending: number
    • idle: number
    • old: number
    • proc.close: number
    • proc.disconnect: number
    • proc.error: number
    • proc.exit: number
    • startError: number
    • stderr: number
    • stderr.error: number
    • stdin.error: number
    • stdout.error: number
    • timeout: number
    • tooMany: number
    • unhealthy: number
    • worn: number
  • get internalErrorCount(): number
  • For integration tests:

    Returns number

  • 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 pendingTaskCount(): number
  • Returns number

    the number of pending tasks

  • 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

  • For diagnostics. Contents may change.

    Returns {
        childEndCounts: {
            broken: number;
            closed: number;
            ended: number;
            ending: number;
            idle: number;
            old: number;
            proc.close: number;
            proc.disconnect: number;
            proc.error: number;
            proc.exit: number;
            startError: number;
            stderr: number;
            stderr.error: number;
            stdin.error: number;
            stdout.error: number;
            timeout: number;
            tooMany: number;
            unhealthy: number;
            worn: number;
        };
        currentProcCount: number;
        ended: boolean;
        ending: boolean;
        internalErrorCount: number;
        maxProcCount: number;
        msBeforeNextSpawn: number;
        pendingTaskCount: number;
        readyProcCount: number;
        spawnedProcCount: number;
        startErrorRatePerMinute: number;
    }

    • childEndCounts: {
          broken: number;
          closed: number;
          ended: number;
          ending: number;
          idle: number;
          old: number;
          proc.close: number;
          proc.disconnect: number;
          proc.error: number;
          proc.exit: number;
          startError: number;
          stderr: number;
          stderr.error: number;
          stdin.error: number;
          stdout.error: number;
          timeout: number;
          tooMany: number;
          unhealthy: number;
          worn: number;
      }
      • broken: number
      • closed: number
      • ended: number
      • ending: number
      • idle: number
      • old: number
      • proc.close: number
      • proc.disconnect: number
      • proc.error: number
      • proc.exit: number
      • startError: number
      • stderr: number
      • stderr.error: number
      • stdin.error: number
      • stdout.error: number
      • timeout: number
      • tooMany: number
      • unhealthy: number
      • worn: number
    • currentProcCount: number
    • ended: boolean
    • ending: boolean
    • internalErrorCount: number
    • maxProcCount: number
    • msBeforeNextSpawn: number
    • pendingTaskCount: number
    • readyProcCount: number
    • spawnedProcCount: number
    • startErrorRatePerMinute: number
  • 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[]>