Skip to content

Instantly share code, notes, and snippets.

@tzechienchu
Created April 25, 2016 09:58
Show Gist options
  • Save tzechienchu/890f9fa119b450e8b9136530109cbc98 to your computer and use it in GitHub Desktop.
Save tzechienchu/890f9fa119b450e8b9136530109cbc98 to your computer and use it in GitHub Desktop.
var kue = require('kue');
// Priority Level
// {
// low: 10
// , normal: 0
// , medium: -5
// , high: -10
// , critical: -15
// };
var CreateJobService = (function () {
var instance;
var queue = kue.createQueue({
prefix: 'queue',
redis: {
port: 6379,
host: '127.0.0.1'
}
});
function init() {
var createJob = function(jobType,payload,jobPriority,cb) {
var job = queue
.create(jobType, payload)
.priority(jobPriority)
.save(function(err){
if (!err) cb(null,job.id);
if (err) cb(err);
});
}
return {
createJob:createJob
}
}
return {
getInstance: function () {
if ( !instance ) {
instance = init();
}
return instance;
}
};
})();
module.exports = CreateJobService;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment