13.0.0 • Published 11 months ago

batch-cluster v13.0.0

Weekly downloads
2,178
License
MIT
Repository
github
Last release
11 months ago

batch-cluster

Efficient, concurrent work via batch-mode command-line tools from within Node.js.

npm version Build status GitHub issues CodeQL Known Vulnerabilities

Many command line tools, like ExifTool, PowerShell, and GraphicsMagick, support running in a "batch mode" that accept a series of discrete commands provided through stdin and results through stdout. As these tools can be fairly large, spinning them up can be expensive (especially on Windows).

This module allows you to run a series of commands, or Tasks, processed by a cluster of these processes.

This module manages both a queue of pending tasks, feeding processes pending tasks when they are idle, as well as monitoring the child processes for errors and crashes. Batch processes are also recycled after processing N tasks or running for N seconds, in an effort to minimize the impact of any potential memory leaks.

As of version 4, retry logic for tasks is a separate concern from this module.

This package powers exiftool-vendored, whose source you can examine as an example consumer.

Installation

Depending on your yarn/npm preference:

$ yarn add batch-cluster
# or
$ npm install --save batch-cluster

Changelog

See CHANGELOG.md.

Usage

The child process must use stdin and stdout for control/response. BatchCluster will ensure a given process is only given one task at a time.

  1. Create a singleton instance of BatchCluster.

    Note the constructor options takes a union type of

  2. The default logger writes warning and error messages to console.warn and console.error. You can change this to your logger by using setLogger or by providing a logger to the BatchCluster constructor.

  3. Implement the Parser class to parse results from your child process.

  4. Construct or extend the Task class with the desired command and the parser you built in the previous step, and submit it to your BatchCluster's enqueueTask method.

See src/test.ts for an example child process. Note that the script is designed to be flaky on order to test BatchCluster's retry and error handling code.

Caution

The default BatchClusterOptions.cleanupChildProcs value of true means that BatchCluster will try to use ps to ensure Node's view of process state are correct, and that errant processes are cleaned up.

If you run this in a docker image based off Alpine or Debian Slim, this won't work properly unless you install the procps package.

See issue #13 for details.

13.0.0

11 months ago

12.1.0

2 years ago

12.0.0

2 years ago

10.4.3

2 years ago

11.0.0

2 years ago

10.4.2

3 years ago

10.4.1

3 years ago

10.4.0

3 years ago

10.2.0

3 years ago

10.3.2

3 years ago

10.1.1

3 years ago

10.3.0

3 years ago

10.3.1

3 years ago

10.0.0

3 years ago

10.0.1

3 years ago

8.1.0

3 years ago

9.1.0

3 years ago

10.1.0

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

9.0.1

3 years ago

9.0.0

3 years ago

7.2.1

3 years ago

7.2.0

3 years ago

7.1.0

3 years ago

7.0.0

3 years ago

6.2.1

3 years ago

6.2.0

3 years ago

6.1.0

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.11.3

4 years ago

5.11.2

4 years ago

5.11.1

4 years ago

5.11.0

4 years ago

5.10.0

5 years ago

5.9.5

5 years ago

5.9.4

5 years ago

5.9.3

5 years ago

5.9.2

5 years ago

5.9.1

5 years ago

5.9.0

5 years ago

5.8.0

5 years ago

5.7.1

5 years ago

5.7.0

5 years ago

5.6.8

5 years ago

5.6.7

5 years ago

5.6.6

5 years ago

5.6.5

6 years ago

5.6.4

6 years ago

5.6.3

6 years ago

5.6.2

6 years ago

5.6.1

6 years ago

5.6.0

6 years ago

5.5.0

6 years ago

5.4.0

6 years ago

5.3.1

6 years ago

5.3.0

6 years ago

5.2.0

6 years ago

5.1.0

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.2.0

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.11.0

7 years ago

1.10.0

7 years ago

1.9.1

7 years ago

1.9.0

7 years ago

1.8.0

7 years ago

1.7.1-0

7 years ago

1.7.0

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago