task-container
Node async task runner. Allows user to create and run Node tasks in seperate process.
The child task should export a function that accepts input data object and a callback as the second parameter or must return a promise.
Example
childTask.js w/ callback
module { }
childTask.js w/ promise
module { return { ; }; }
main.js
const TaskContainer = ;const TaskRunner = TaskRunner; let tc = ;tc; //or async { try let result = await tc; catchex console; };
API
new TaskContainer([options])
options
maxTaskRunners: number //default: require('os').cpus().length - 1, maxCallsPerTaskRunner: number //default: Infinity
-
maxTaskRunners
Number of child processes to spawn for handling tasks. If all child processes are currently busy the task will be queued and handled as soon as a handler is free. Task are processed in FIFO order.
-
maxCallsPerTaskRunner
Number of times to call a child task before recycling the process (killing current child process and starting a new one). This can be used to manage memory leaks until they can be fixed.
taskContainer.run(script, [data])
script
This is the path to the module you wish to run as a task. This script should export a method which takes an object as it's first parameter and a callback as the second.
Example:
module { //do work here ;}
data
Object you wish to be passed to the task.
callback
Method which gets called when task has completed.
taskRunner.run(script, [data])
Works the same as TaskContainer, but is for running a single task. do not use to run multiple tasks simultaneously, use TaskContainer