options
- configuration object passed in the constructorconcurrency
- number of worker processes to be spawned. The default is the number of CPU cores -1workerType
- type of the worker. Possible values are TaskBatka.WORKER_CHILD_PROCESS and TaskBatka.WORKER_THREAD
registerTask(taskName, pathToTask, persistent)
- registeres a new TasktaskName
- a name for the task to be used later for the task executionpathToTask
- an absolute path to the task definition filepersistent
- Optional. tells the workers to keep task instances and reuse them. Default is false
addTask(task, data, method)
- executes the task in a worker process. Returns a promise to be fullfiled with the result or the errortask
- the name provided in the task registrationdata
- object with params that will be passed to the task's run method while executionmethod
- Optional. Which method of the task should handle this execution. The default is therun
method
addToWorker(workerIndex, task, data, method)
- executes the task in a given worker process. Returns a promise to be fullfiled with the result or the errorworkerIndex
- zero based index of the rokertask
- the name provided in the task registrationdata
- object with params that will be passed to the task's run method while executionmethod
- Optional. Which method of the task should handle this execution. The default is therun
method
executeOnAll(task, data, method)
- execute a task on all workers and returns a promise to be fullfiled with the result or the errorquit()
- terminate all worker processes allowing the host process to exitquitWhenEmpty()
- wait for all running tasks to finish and terminats the worker processeson(eventType, handler)
- registers an event handler
run(params)
- this is where the task code goes. The run method must either return a promise or call thecomplete
orerror
method insideparams
- a object with params passed fromBatka.execute
init
- any code needed for task initialization.complete(result)
- completes the curent task with theresult
allowing the worker to take other tasksresult
- the result from the task esecution. It will be used to resolve the promise returned fromBatka.addTask
error(error)
- completes the curent task with theresult
allowing the worker to take other taskserror
the error message if the task fails. It will be used to reject the promise returned fromBatka.addTask
sendMessage(type, data)
- sends an event to the main process without completing the current task