Awesome
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->Table of contents
<!-- END doctoc generated TOC please keep comment here to allow auto update -->adonis5-bullmq
Tagline
BullMQ provider for Adonis5
Installation
npm i adonis5-bullmq
node ace invoke adonis5-bullmq
Usage
Create your props interface and enums
// file: Contracts/QueueInterfaces.ts
export interface TestProps {
name: string
}
export enum QueueNamesEnum {
'TestJob' = 'TestJob'
}
Create queue listener
// 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
})
}
}
Emit 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' })
}
}