Last active
August 29, 2015 14:11
-
-
Save FirstWhack/4ea07f0a11351c74fce8 to your computer and use it in GitHub Desktop.
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
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