Skip to content

Instantly share code, notes, and snippets.

@Jhawins

Jhawins/check.js

Last active Aug 29, 2015
Embed
What would you like to do?
function runCheck(host, cb) {
console.log('Checking for life at ' + host + ' we checked '+ checks + ' times so far');
var checkReq = http.get(host, function(res) {
console.log("Got response: " + res.statusCode);
ret = 'online';
checkReq.clearTimeout();
console.log('Timeout cleared and sending them on their way');
cb(true); // we are solid
}).on('error', function(e) {
console.log('error' + e);
turnOn();
cb(false);
});
// I hate waiting.. Let's set a timeout
checkReq.setTimeout( 4000, function( ) { // 4 seconds is usually enough
console.log('I timed out bro, lets try to turn it on?');
checkReq.abort();
console.log('Aborted : moving to `turnOn()`');
turnOn();
cb(false);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.