Tagline
BullMQ provider for Adonis5
npm i adonis5-bullmq
node ace invoke adonis5-bullmq
// file: Contracts/QueueInterfaces.ts
export interface TestProps {
name: string
}
export enum QueueNamesEnum {
'TestJob' = 'TestJob'
}
// file commands/QueueListener.ts
import BullMQ from '@ioc:Adonis/Addons/BullMQ'
import {TestProps, QueueNamesEnum} from 'Contracts/QueueInterfaces'
export default class QueueListener extends BaseCommand {
/**
* Command Name is used to run the command
*/
public static commandName = 'queue:listener'
public static settings = {
loadApp: true,
}
run(){
BullMQ.worker<TestProps, TestProps>(QueueNamesEnum.TestJob, async (job) => {
console.log(job.data)
// handle your job
return job
})
}
}
// anyAppFile.ts
import BullMQ from '@ioc:Adonis/Addons/BullMQ'
import {TestProps, QueueNamesEnum} from 'Contracts/QueueInterfaces'
const queue = BullMQ.queue<TestProps, TestProps>(QueueNamesEnum.TestJob)
export default class IndexController {
async send(){
await queue.add('mytestJob', { name: 'anyName' })
}
}