Created
January 30, 2014 20:32
-
-
Save mcqueenorama/8718128 to your computer and use it in GitHub Desktop.
setInterval in sails bootstrap
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.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