adonis-queue
An addon/plugin package to provide driver-based job queueing services in AdonisJS 4.0+
Getting Started
adonis install adonisjs-queue
Usage
Add a job file to the jobs folder using the command. The command below creates the file
app/Jobs/SendEmail.js
. The queue flag in the command is for setting the queue priority channel. The queue flag has only 2 possible values: high and low
$ adonis make:job SendEmail $ adonis make:job SendEmail --queue=low
OR
$ node ace make:job SendEmail
Installation Instructions
See the instructions.md file for the complete installation steps and follow as stated.
Writing A Job
/** @type {typeof import('adonisjs-queue/src/Job')} */const Job = /** @type {typeof import('@adonisjs/mail/src/Mail')} */const Mail = { return 'low' } { superarguments thistimeOut = 100; // seconds thisretryCount = 0; thisretryUntil = 200; // seconds thisdelayUntil = Date // optional, omit this line if not required } async { //.... console await link let _data = linkdata // arguments passed into the constructor let error = null let result = null try result = await Mail await link catcherr error = err result = undefined await link finally await link return { error === null ? : }; } { console } { console this // remove the job from the queue (when the job fails after all retries) } { console } { console } moduleexports = SendEmail
Open the
start/events.js
file of an AdonisJS Framework installation and add the following code to it (This package encourages the use of the standard event bus for AdonisJS)
'use strict' /** @type {typeof import('@adonisjs/framework/src/Event')} */const Event = /** @type {typeof import('adonisjs-queue/src/Queue')} */const Queue = const SendEmail = Event
Then, go to the
start/routes.js
file of an AdonisJS Framework installation and add the following code to it
/** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */const Route = Route
Possible Gocthas
If the select()
method is explicitly called before a (chained) call andDispatch()
OR dispatch()
is made on the Queue
object, the queue getter value on a job instance (job.queue
) is automatically overridden by the value passed to the select method like so select('low')
. So, be well aware of how calling select
explicitly affects things.
More
You can also access the queue instance via the AdonisJS Http Context in a controller/middleware
'use strict' const SendEmail = async { let tenant_id = session let email = request await queue } moduleexports = WorksController
License
MIT
Running Tests
npm i
npm run lint npm run test
Credits
Contributing
See the CONTRIBUTING.md file for info
Support
Coolcodes is a non-profit software foundation (collective) created by Oparand - parent company of StitchNG, Synergixe based in Abuja, Nigeria. You'll find an overview of all our work and supported open source projects on our Facebook Page.
Follow us on facebook if you can to get the latest open source software/freeware news and infomation.
Does your business depend on our open projects? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.