Ease the implementation of multi processing accross your microservices
The goal of this library is to ease the implementation of multi processing accross your existing microservices. Relieve aims to give a reusable design pattern using process forks. It also eases communication with child processes with an high-level abstraction.
For example, with a CallableTask:
//task.js
//just export a module in the child process
module.exports = {
print: (str) => {
console.log(str)
},
data: () => {
//return some async data
return Promise.resolve({foo: 'bar'})
}
}
Then from your master, just call the task:
//worker.js
var CallableTask = require('relieve/tasks/CallableTask')
var task = new CallableTask('task.js')
task.start()
.then(() => {
task.call('print', 'hello world')
return task.get('data')
})
.then(d => {
//d is {foo: 'bar'}
})
Relieve is based on a design pattern containing:
The task can be used without a Worker, but the Worker helps managing workflows.
The task will implement a child process using fork
. It'll make sure that there is an ipc channel open so that Workers and Tasks can communicate.
There are different tasks implementations:
ChildProcess.fork
in a TaskChildProcess.fork
. It gives the ability to start, restart or kill a Taskcall
or get
script methods remotelyDifferent kind of Workers for different use cases. Every Worker takes one or more tasks and handles them.