1.0.0 • Published 4 years ago

adonisjs-bull-queue-provider v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Install

Install with npm:

npm install adonisjs-bull-queue-provider

Install with yarn:

yarn add adonisjs-bull-queue-provider

Config

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

Make a Job

You can initiate a Job using adonis cli

adonis make:job JobName

Import Bull with

use('Bull/Queue')

Using

  • 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);

Exemple

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();