Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BatchCluster

BatchCluster instances manage 0 or more homogenious child processes, and provide the main interface for enqueing 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.

Hierarchy

  • BatchCluster

Index

Constructors

constructor

Accessors

ended

  • get ended(): boolean

internalErrorCount

  • get internalErrorCount(): number

meanTasksPerProc

  • get meanTasksPerProc(): number
  • Returns number

    the mean number of tasks completed by child processes

pendingTasks

  • get pendingTasks(): number

spawnedProcs

  • get spawnedProcs(): number

Methods

end

  • end(gracefully?: boolean): Promise<void>
  • Shut down this instance, and all child processes.

    Parameters

    • Default value gracefully: boolean = true

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

    Returns Promise<void>

enqueueTask

  • enqueueTask<T>(task: Task<T>): Promise<T>
  • 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 attemped on an idle BatchProcess

on

  • on(event: "startError", listener: function): void
  • on(event: "taskData", listener: function): void
  • on(event: "taskError", listener: function): void
  • on(event: "endError", listener: function): void
  • on(event: "beforeEnd", listener: function): void
  • on(event: "end", listener: function): void
  • Emitted when a child process has an error when spawning

    Parameters

    • event: "startError"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • Emitted when tasks receive data, which may be partial chunks from the task stream.

    Parameters

    • event: "taskData"
    • listener: function
        • (data: Buffer | string, task: Task<any> | undefined): void
        • Parameters

          • data: Buffer | string
          • task: Task<any> | undefined

          Returns void

    Returns void

  • Emitted when a task has an error

    Parameters

    • event: "taskError"
    • listener: function
        • (err: Error, task: Task<any>): void
        • Parameters

          • err: Error
          • task: Task<any>

          Returns void

    Returns void

  • Emitted when a child process has an error during shutdown

    Parameters

    • event: "endError"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • Emitted when this instance is in the process of ending.

    Parameters

    • event: "beforeEnd"
    • listener: function
        • (): void
        • Returns void

    Returns void

  • Emitted when this instance has ended. No child processes should remain at this point.

    Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns void

pids

  • pids(): Promise<number[]>
  • Exposed only for unit tests

    Returns Promise<number[]>

    the spawned PIDs that are still in the process table.

Generated using TypeDoc