Created
April 25, 2016 09:58
-
-
Save tzechienchu/890f9fa119b450e8b9136530109cbc98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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