npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adonis-bull-provider

v2.1.3

Published

Bull provider for adonis js

Downloads

138

Readme

Adonis bull provider

Gives nice adonis-like interface with bull library.

Installation

  1. npm i adonis-bull-provider --save
  2. register provider inside start/app.js
const providers = [
    //...
    'adonis-bull-provider/Providers/AdonisBullProvider'
]

const aceProviders = [
    //...
    'adonis-bull-provider/Providers/AdonisBullCommand' // if you want run queue with a command
]
  1. make config/redis.js as per instructions here
module.exports = {
    connection: 'local',
    
    local: {
        host: GET_THIS,
        port: GET_THIS,
        password: GET_THIS,
        db: GET_THIS
    },
}
  1. add config/bull.js configuration (optional)
module.exports = {
    prefix: 'prefix', // prefix all queues if multiple projects use same database
    defaultRedis: 'local', // as defined in config/redis.js. Can be overridden for each queue. Defaults to local
    queueDirectory: 'app/Queues', //where are your queue files, defaults to this value,
    onBoot: true, // to determine whether to automatically register queues or not
    arenaPrefix: '', // prefix for bull-arena if you include it
    arenaUser: 'admin', // used for auth on bull-arena server
    arenaPassword: '' // used for auth on bull-arena server
    arenaPort: 1212 // port used to serve bull-arena
}

Done!

Use

Inside queue directory (defaults to app/Queues make handlers. handlers look like this

queueDir/SampleQueue


const BaseQueue = use('Queue/BaseQueue')

class SampleQueue extends BaseQueue {
    
    static get key() {
        return 'queueName'
    }
    
    async eventName(payload) {
        //handle jobs with name 'eventName'
    }
    
    async anotherEventName() {
        //handle jobs with name 'anotherEventName'
    }
    
    async defaultHandle(payload ) { 
        //if method with job name is not fond this is executed
    }
}

module.exports = SampleQueue

Besides these, you can also add:


    static get redis() {return 'local'} //optional, if you want to use different redis conection
    
    static get config() {return {}} //optional, custom config for queue creation. See this in bull documentation
    
    static createQueue() {
        //NOT RECOMMENDED!!! Override way of creating queue.
        return super.createQueue()
    }

When adding job:

    const SampleQueue = use('Queue')('SampleQueue') //this returns native bull queue objects
    await SampleQueue.add({data: 'payload'}, {delay: 2000})
    return {}

Starting Queues

Queues are registered automatically on server start by default. But you can include onBoot: false in config/bull.js to disable automatic registration.

If you disable automatic registration, it means you want to use the command option instead.

Using Adonis command to start queues

Use this command to start the queues:

adonis queue:listen

To also run bull-arena alongside, add --arena

adonis queue:listen --arena

bull-arena will run on the port you specify with arenaPort (defaults to 1212) in config/bull.js.

Exceptions

To handle errors, define onError(error, payload) method on your queues. It'll be called if an error occurs while processing a job

closeAll

When you register this provider, problem will arise: ace commands will not exit. That happens because redis connections are not closed. For that reason (or for any reason tou might need) you may call closeAll() method.

Inside start/hooks.js

hooks.before.aceCommand(async () => {
    const {closeAll} = use('Queue/Helpers')
    await closeAll()
})

Note If you have overridden createQueue method on Queue handlers, this may not work properly

Thanks

Special thanks to creators of AdonisJs and bull