BullMQ
Search…
Named Processor
When a Worker is instantiated, the most common usage is to specify a process function.
Sometimes however, it is useful to be able to specify more than one function to process a job for a specific condition:
1
const worker = new Worker(
2
'queueName',
3
async job => {
4
switch (job.name) {
5
case 'taskType1': {
6
await doSomeLogic1();
7
break;
8
}
9
case 'taskType2': {
10
await doSomeLogic2();
11
break;
12
}
13
}
14
},
15
{ connection },
16
);
Copied!
You could use a simple switch case to differentiate your logic, in this example we are using the job name.
This was a feature in the Bull package, but it creates a lot of confusion, so in order to provide an alternative, you can use this pattern. See #297 and #69 as reference
Copy link