Scheduled & queued jobs for Adonis 4.x, backed by beanstalkd, ironMQ, and/or AWS SQS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
examples/config
providers
src
templates
test/functional
.gitignore
.npmignore
CONTRIBUTORS.md
LICENSE
README.md
instructions.js
instructions.md
japaFile.js
package-lock.json
package.json

README.md

Adonis Ironium

An Ironium provider for the Adonis 4.x framework.

Easy integration of job queues backed by beanstalkd, ironMQ, and Amazon SQS

Installation & Configuration

See instructions.md

adonis install adonis-ironium

Usage

Command List

Command Description
adonis make:job Make a new Job Queue
adonis ironium:listen Start the queue listener

Creating your first job queue

At it's most basic, a job queue provides an async handle method that job data is passed into, upon which it operates. This could be anything from simply the user id for a new user we want to send a welcome email, or a collection of data needing further processing that doesn't make sense to occur during a regular user request.

The handle method is the only requirement!

Name Required Type Static Description
handle true function false An async function that is called for this job.

Here's an example.

The only real limitation is job payload size, which is dictated by the queue backend:

  • AWS and IronMQ: 256k
  • beanstalkd: 64k by default, but configurable

Dispatching jobs

Dispatching jobs is pretty straightforward...

const ironium = use('Ironium')
const queueName = 'Example'
const job = {
  message: 'This is my test job!'
}

const jobID = ironium.dispatch(queueName, job)

It will return a job ID, and process your job behind the scenes.

You can also pass in an array of jobs, and optionally specify a delay in a format parsable by ms:

const ironium = use('Ironium')
const queueName = 'Example'
const delay = '2hr'
const job = {
  message: 'This is my test job!'
}

const jobID = ironium.dispatch(queueName, job, delay)
const ironium = use('Ironium')
const queueName = 'Example'

const jobs = [
  { message: 'This is my test job!' },
  { message: 'Another test job!' },
]

const jobID = ironium.dispatch(queueName, jobs)

Reminder

Queued jobs won't process until you fire up one or more queue workers with the ironium:listen command.

Important Note

If you wish to dispatch jobs from within jobs, use does not appear to behave as one might expect, so instead you should use ioc.make() like so:

const { ioc } = require('@adonisjs/fold')

class Example {
  async handle (job) {
    const Ironium = ioc.make('Ironium')
    const Logger = ioc.make('Logger')

    const jobId = await Ironium.dispatch('AnotherJob', anotherPayload)
    Logger.info('Dispatching Job(s): ', jobId)

    return
  }
}

Thanks

Heavily inspired by Adonis Kue, thanks Nick Rempel for that!

Also to Harminder Virk for creating Adonis.