Skip to content

Instantly share code, notes, and snippets.

@oakinogundeji
Created April 15, 2016 11:48
Show Gist options
  • Save oakinogundeji/56e83a085ad750486ebc32dc1533b762 to your computer and use it in GitHub Desktop.
Save oakinogundeji/56e83a085ad750486ebc32dc1533b762 to your computer and use it in GitHub Desktop.
Implementing monq as a job queueing solution
/**
*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