kue-helpers
v1.1.1
Published
Simple, high-level promise-based helpers for Kue (the Node.js job Queue).
Readme
kue-helpers
Simple, high-level promise-based helpers for Kue (the Node.js job Queue).
yarn add kue-helpersUsage
The default export is a function which has one required parameter: a redis url to provide to Kue. When supplied with a redis url, that function will return an object with the helper methods.
const kueHelpers = require('kue-helpers')(REDIS_URL)
kueHelpers.getQueue() // the queue object from KueHelper Methods
getQueue
No parameters.
Returns Kue's queue object by calling kue.createQueue.
enqueueJob
Parameters
- Job Name (String)
- Job Data (Object)
Returns a promise that executes the then on Kue's complete event, and rejects on Kue's failed event.
Example
const promise = enqueueJob('ExpensesBulkUpdate', { expenses, upsert: true })handleResponse
Parameters:
- A promise
- The done callback from Kue's
queue.processmethod
Example
kue.createQueue(...).process(jobName, (job, done) => {
handleResponse(methodThatReturnsAPromise(), done)
})processAsyncJob
Parameters:
- Database connection (Function). A function to get the status of the database connection. Expects an object to be returned with a property called
readyStatethat represents that connection status of the database. A ready state of 1 means the database is connected and a ready state of anything other than 1 means that database isn't connected and will cause an error to be thrown in the job. - Job Name (String)
- async Function
Example
processAsyncJob('ExpensesBulkUpdate', async job => {
const { expenses, upsert } = job.data
... etc
})