Worker extension for bullmq.
This worker allows you to register processors for specific job names within the queue. The example shows how this package is used.
bullmq is a peer dependency, you'll need to install it yourself.
npm i @art-of-coding/routed-worker bullmq [--save]
import RoutedWorker, {
Job
} from './index'
// create a new routed worker with the queue name 'Example'
const worker = new RoutedWorker('Example')
// Interface for job data
interface JobData {
name: string,
age: number
}
// Add a route, this is the job name (in this case, 'Greeting')
worker.on('Greeting', async (job: Job<JobData>) => {
// Do something and return a result
return `Hello, ${job.data.name}!`
})
// start the worker (required!)
worker.start()
Copyright 2020 Art of Coding.
This software is licensed under the MIT License.