worker_utils
v1.0.19
Published
Crossplatform process manager for running node applications with high-availability and custom priority
Downloads
32
Maintainers
Readme
#Worker Utils
Starts workers with a set priority (to run background tasks or to respond in high urgency), with keepAlive option to restart failing processes. ##Installation
npm install worker_utils --save
##Usage
const
os = require('os'),
WorkerUtils = require('./worker_utils.js');
var workerUtils = new WorkerUtils("Background Worker");
workerUtils.setVerbose(true);
workerUtils.run('./script_that_does_a_very_long_job.js', {
verbose : true,
priority : 10,// (below normal); ommit it and you will get normal
//flags : '-c', //put here the flags you want passed to node
argv : 'this_string_is_going_to_be_passed_as_an_argument', // the arguments string for you the child process
keepAlive : true // if the process craches, should we restart it?
//_restartLimit : 3, // this is the default restart limit (how many times)
//_restartDelay : 50 // this is the default restart delay (how much delay between each time)
}, function(proc, restarts){
if(proc){
console.log('proccess started ' + proc.pid + ' with a restart of ' + restarts);
}else{
console.log('proccess creation failed');
}
});
Notes
Windows
If you wish to use custom priority on a script, you might need write access on the running dir as wmic calls sometimes write a temp batch file
Nix
Uses nice for priority handling