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:
const worker = new Worker(
'queueName',
async job => {
switch (job.name) {
case 'taskType1': {
await doSomeLogic1();
break;
}
case 'taskType2': {
await doSomeLogic2();
break;
}
}
},
{ connection },
);
You could use a simple switch case to differentiate your logic, in this example we are using the job name.
Last modified 1yr ago