adonis5-bullmq
v3.2.0
Published
Adonis 5 bullmq provider
Downloads
1,011
Readme
Table of contents
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' })
}
}