sails-hook-bulljs
v1.0.1
Published
A bull wrapper for sails
Downloads
55
Readme
sails-hook-bulljs
Sails.js hook to use bull package for handling distributed jobs and messages.
Based on sails-hook-bull package (👍).
Installation
Install it via npm:
npm install sails-hook-bulljs --save
or
yarn add sails-hook-bulljs
Configuration
You can set some parameters in config/bulljs.js
to override defaults options for all queues.
module.exports.bulljs = {
redis: {
port: 6379,
host: '127.0.0.1',
db: 0,
password: ''
}
}
See bull.queue for more information.
Examples
Bull queue definition in api/queues/my-queue.js
module.exports = {
queueName: 'my-queue',
// if redis already defined as an object, url will be ignored
url: 'redis://127.0.0.1:6379',
opts: {
limiter: {
max: 1000,
duration: 5000
}
},
/**
* If "false" it only allows adding object to queue. It does not process a queue or fire events.
* Great option for backend workers.
* @return {Boolean} True by default.
*/
guard: async => {
return true
},
process: async job => {
// process queue
},
onCompleted: async job => {
// do something when completed
},
onRemoved: async job => {
// do something when job removed
},
onError: async err => {
// do something on error like Redis connection failure etc.
},
onFailed: async (job, err) => {
// do something when process fails
},
};
You can define queues with options:
module.exports = {
queueName: 'my-queue',
process: {
name: 'my-super-queue',
concurrency: 1,
processor: (job, done) => {
// do something...
done();
}
}
};
Adding jobs to a queue:
// api/controllers/someController.js
module.exports = {
someAction: function(req, res) {
sails.hooks.bulljs.myQueue.add({
param: 'value'
})
}
};
License
MIT