Install with npm:
npm install adonisjs-bull-queue-provider
Install with yarn:
yarn add adonisjs-bull-queue-provider
Make sure to register the provider inside start/app.js
file.
const providers = ["adonisjs-bull-queue-provider/BullProvider"];
Config redis with adonis
And then your .env
file
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
You can initiate a Job using adonis cli
adonis make:job JobName
use('Bull/Queue')
- Make a job file with adonis cli
- Call a job to make a service
const job = await JobName.add("nameJob", { data });
If you will use hooks, you can do this way
const job = await JobName.add("nameJob", { data });
job.waiting(data).completed(data);
const Bull = use("Bull/Queue");
class JobName {
constructor() {
this.queue = Bull.init("JobName");
this.process();
}
add(name = null, data = null, options = null) {
// Data to process in queue
this.queue.add(name, data, options);
return this.hooks();
}
process() {
this.queue.process("*", async (job, done) => {
try {
console.log(job.data);
done(null, { msg: "done" });
} catch (error) {
throw new Error(error);
}
});
}
}
module.exports = new JobName();