Created
April 15, 2016 11:48
-
-
Save oakinogundeji/56e83a085ad750486ebc32dc1533b762 to your computer and use it in GitHub Desktop.
Implementing monq as a job queueing solution
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
/** | |
*Module dependencies | |
*/ | |
//----------------------------------------------------------------------------- | |
var | |
monq = require('monq'), | |
config = require('../config/config'); | |
//============================================================================= | |
/** | |
*Create monq instance | |
*/ | |
//----------------------------------------------------------------------------- | |
var client = monq(config.dBURL); | |
//============================================================================= | |
/** | |
*Create job queue | |
*/ | |
//----------------------------------------------------------------------------- | |
var queue = client.queue('default'); | |
//============================================================================= | |
/** | |
*Define job creator helper | |
*/ | |
//----------------------------------------------------------------------------- | |
function newJob(data, req, res) { | |
return queue.enqueue('testing', data, function (err, job) {//the 'producer' | |
//is enqueueing the 'testing' job with the provided 'data' onto the 'default' queue, NB | |
//this 'testing' job is hardcoded! | |
console.log('new job has been enqueud by server with processID: %s', process.pid); | |
req.app.emit('newJob'); | |
return res.status(200).json('Processing job!'); | |
}); | |
} | |
//============================================================================= | |
/** | |
*export module | |
*/ | |
//----------------------------------------------------------------------------- | |
module.exports = { | |
newJob: newJob, | |
client: client | |
}; | |
//============================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment