bulkhead-kue
v0.0.1
Published
A Bulkhead service that allows SailsJS projects to easily utilize LearnBoost's Kue.
Downloads
1
Maintainers
Readme
bulkhead-kue
A Bulkhead plugin that easily integrates LearnBoost's Kue into a SailJS project.
Installation
npm install bulkhead-kue
Then, in the config/bootstrap.js
file of your SailsJS project directory, replace the default cb()
with:
require('bulkhead').plugins.initialize(sails, cb);
If you are using Bulkhead-Kue
with Bulkhead-Test, the suite has to be lifted like this:
var Suite = require('bulkhead-test');
Suite.lift(null, function() {
QueueService.flush(queueName);
});
Usage
To create new jobs in a queue, do the following:
var QueueService = require('bulkhead-kue');
QueueService.create('SomeQueue', 'SomeJobType', { name: 'bob' }, function(results, job) {
// Callback that is fired when the job is processed.
console.log(results.name) // Outputs 'bob'
console.log(job.id) // Outputs 1
}, function(err, results) {
// Callback that is fired when the job is saved into the queue
console.log(results.response().name) // Outputs 'bob'
});
NOTE:
If you create a new job on a queue that has not been created yet,
.create()
will create the queue as well.
To get access to the queue and it's Kue methods, do the following:
QueueService.queue('SomeQueue');
To find jobs by their processing state, the search criteria should be a string:
QueueService.find('inactive', function(err, result) {
console.log(result.response().name); // Outputs 'bob'
});
To find jobs by their ID, the search criteria should be a number:
QueueService.find(1, function(err, result) {
console.log(result.response().name); // Outputs 'bob'
});
To find jobs by complex criteria, the search criteria should be an object:
QueueService.find({
type: 'SomeJobType',
state: '*',
from: 0,
to: -1,
order: 'desc'
}, function(err, result) {
console.log(result.response().name); // Outputs 'bob'
});
To process all jobs in a queue, do the following:
QueueService.process(queueName, type, null, function(job, next) {
// Callback that is fired per job being processed
console.log(job.data.name) // Outputs 'bob'
next(undefined, job.data); // Moves on to the next job to process
});
Read the official Kue documentation for more advanced usage.