Skip to content

Instantly share code, notes, and snippets.

@mcqueenorama
Created January 30, 2014 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcqueenorama/8718128 to your computer and use it in GitHub Desktop.
Save mcqueenorama/8718128 to your computer and use it in GitHub Desktop.
setInterval in sails bootstrap
module.exports.bootstrap = function (cb) {
console.log('in bootstrap');
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
});
//ping the queue each 10 seconds
var the_interval = 10 * 1000;
console.log('calling setInterval');
setInterval(function() {
console.log('setting ping timer');
var http = require('http'), options = {
host : "localhost",
port : 6769,
path : '/test_start?job_name=ping',
method : 'GET'
};
var webservice_data = "";
var webservice_request = http.request(options, function(webservice_response)
{
console.log('sending ping to queue');
webservice_response.on('error', function(e){ console.log(e.message); });
webservice_response.on('data', function(chunk){ webservice_data += chunk;});
webservice_response.on('end', function(){console.log(webservice_data);});
console.log('sent ping to queue');
});
}, the_interval);
console.log('done with bootstrap');
// It's very important to trigger this callack method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
cb();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment