0.4.0 • Published 7 years ago
process-scheduler v0.4.0
process-scheduler
Manage node workers.
Features:
- Schedule processes with crontab rules
- Concurrency rules
- Dependency rules
Installation
$ npm install --save process-scheduler
Usage
const Scheduler = require('process-scheduler');
var scheduler = new ProcessScheduler(config);
scheduler.on('change', handleChange);
scheduler.on('message', handleMessage);
scheduler.schedule(options);config: general scheduler configuration:
threads: the maximum number of threads that should be used. This can be a number or you can assign a number of threads per processtype(see options). Giving a number is like assigning the number of threads to the default type.
options is an array of objects that have the following structure:
id: identifies the process (mandatory)worker: the worker that the scheduler will fork (mandatory)type: type of process. Default is'default'noConcurrency: an array of process ids with which this process should not be run concurrentlydeps: an array of process ids that should be triggered when this process is triggered. If the appropriatenoConcurrencyrule exists, the depenency processes will be executed only after this process has finished. Thedepsarray can also nest an object with theoptionsstructure.scheduler.schedulewill fail if circular dependencies are detected.cronRule: a cron rule for executing the process. If not given the process is triggered once immediatly. See node-schedule for accepted input.immediate:trueorfalseweather to execute the process once immediately or not. Ifundefinedthe process is executed immediately only if nocronRuleis givenretryTimeout: timeout in seconds after which the process should be restarted in case of failure
Events:
change: notifies a change of status. An object with the follwing structure is passed:id: id of the process configuration that launched the processpid: the id of the process that updated its statusstatus: Possible status arequeued,running,success,errormessage: the error message ifstatusiserror.
message: notifies that process has sent a message. The message sent by the process is in thedatapropertyid: id of the process configuration that lanuched the processpid: id of the process that sent a messagedata: data sent by the process