CHAT APP WORKERS
This app uses bull.js with is Redis-based queue for Node.
STRUCTURE
The main goal is to communicating with external services (slack, autopilot, etc...). This lead to specific structure, made of different queues specific for each service.
To call it just return object with queue value equal to corespondent queue name and data as object with method and params.
How to use
Facing all over again same issues we decide to put all hard logic into sequence factory.
This allow to build speed up the process of adding new jobs. Let's take a look into this:
CLI
At first install cli:
npm i chat-app-workers-cli -g
and then call generate-workers name
, where name is desire name of directory to be created and follow up with selecting type of your new queue.
File structure
generate-workers
command will create a directory with 3 files. You need to interact with all of it. At first set name for queue in index.js file.
This should be imported from @autopilot/chat-app-core. You don't need to worry about importing it. It'll be done automatically.
Then, modify you eventListener.js file if you need any event to catch. Then you are ready to go and write main content inside `processors.js' file.
The processors.js file should be structure this way:
module.exports = {
__default__: (job, app) => {
return {
queue: queues.slack.name,
params: {
method: 'chat.postMessage',
params: { token: 'xxx' }
},
extraData: {
name: 'name'
},
nextStep: 'secondStep'
}
},
secondStep: (job) => {
console.log(job.data)
const { res } = job.data
return {
queue: queues.slack.name,
params: {
method: 'chat.delete',
params: {
token: 'xxx',
channel: '1',
ts: '123'
},
}
}
}
}