proc-runner
Run child processes synchronously and print nice status to terminal. Designed to print and update status nicely inline with other console output. All console output is abstracted so you can easily set printStatus: false and implement your own logger (see status-handler.js for inspiration).
Usage
Get runner:
const runner = require('proc-runner')({printStatus: true})
Add commands:
runner.addProc({name: 'display_name', exec: 'node', args: ['-e', "process.exit(0)"]});
The argument to addProc can be an object or array of objects. Fields available for use are:
- exec: path to executable (required)
- name: display name
- args: arguments to pass to executable (array of strings)
- timeout: time out if process is not finished faster than this (ms) - set to 0 for no time out
- startTimeout: time out if process does not write to stdout or finish faster than this (ms) - set to 0 for no time out
- onStarted: function to call on started event for this process
- onDone: function to call on done event for this process
- onError: function to call on error for this process
- onTerminated: function to call on terminated event for this process
- onSuccess: function to call on success event for this process
- onData: function to call on data event for this process
Allow the runner to terminate itself when idle instead of emitting idle event:
runner.finalize()
Listen for various events:
runner;runner;runner;runner;runner;runner;runner;runner;
Examples
More complicated example showing error handling, processes timing out, changing concurrent process count, and waiting for current processes to complete before adding more:
Here's the code for simple example above, for more examples see the samples folder in this repository.
const proc_count = 10;console; const runner = printStatus: true;for const _ of proc_count runner; runner; runner;
Todo
- Remove terminal-kit dependency or make optional, maybe move terminal output to separate package
- Add coverage badge