Adonis Kue Provider
A Kue provider for the Adonis framework.
This library provides an easy way to get started with an asynchronous job queue for AdonisJS.
Install
npm install --save adonis-kue
Configure
Register the kue provider in start/app.js
:
const providers = ... 'adonis-kue/providers/KueProvider'
Register the commands provider in start/app.js
:
const aceProviders = ... 'adonis-kue/providers/CommandsProvider'
Register the jobs in start/app.js
:
const jobs = ... 'App/Jobs/Example'
And then export the jobs
array:
moduleexports = providers aceProviders aliases commands jobs
Add a configuration file in config/kue.js
. For example:
'use strict' const Env = moduleexports = // redis connection connection: Env
Usage
Command List
Command | Description |
---|---|
adonis kue:listen |
Starting the listener |
adonis make:job |
Make a new Job (Queue) |
Starting the listener
Starting an instance of the kue listener is easy with the included ace command. Simply run ./ace kue:listen
or adonis kue:listen
.
Creating your first job
They expose the following properties:
Name | Required | Type | Static | Description |
---|---|---|---|---|
concurrency | false | number | true | The number of concurrent jobs the handler will accept |
key | true | string | true | A unique key for this job |
handle | true | function | false | A function that is called for this job. |
Dispatching jobs
Now that your job listener is running and ready to do some asynchronous work, you can start dispatching jobs.
const kue = const Job = const data = test: 'data' // Data to be passed to job handleconst priority = 'normal' // Priority of job, can be low, normal, medium, high or criticalconst attempts = 1 // Number of times to attempt job if it failsconst remove = true // Should jobs be automatically removed on completionconst jobFn = { // Function to be run on the job before it is saved job}const job = kue // If you want to wait on the result, you can do thisconst result = await jobresult
Thanks
Special thanks to the creator(s) of AdonisJS for creating such a great framework.