adonis-bull-queue-provider

1.0.1 • Public • Published

Install

Install with npm:

npm install adonis-bull-queue-provider

Install with yarn:

yarn add adonis-bull-queue-provider

To Using

To start use the package, you will need create a new file. start/jobs.js You should import yours jobs to this file, example:

const TestJob = use('App/Jobs/TestJob')
module.exports = [TestJob]

Config

Make sure to register the provider inside start/app.js file.

const providers = ["adonis-bull-queue-provider/provider"];

Config redis with adonis and then your .env file

  REDIS_HOST=127.0.0.1
  REDIS_PORT=6379

Commands

Make a Job

You can initiate a Job using adonis CLI

adonis make:job Folder/JobName

Listener

You can initiate listen jobs with

adonis job:listen

Add item in queue.

    const Queue = use("Bull/Queue");
    class{
        method(ctx){
            Queue.add("TestJob", { msg: "Params to queue..." })
        }
    }

Example

  • Make a job file with adonis cli. You can use Bull events if necessary.
class TestJob {
  constructor () {
    this.key = 'TestJob'
    this.options = {
      delay: 5000
    }
  }
 
  async handle (job, done) {
    job.progress(1)
    console.log('Logic Here!!!')
    job.progress(100)
    done(null, { msg: 'okay' })
  }
  
 async errorEvent (error) {
    console.log('Queue error')
  }
 
  async waitingEvent (jobId) {
    console.log('Queue waiting')
  }
  other....
}
module.exports = new TestJob()

Package Sidebar

Install

npm i adonis-bull-queue-provider

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

8.4 kB

Total Files

8

Last publish

Collaborators

  • williamsouzaa