Last active
May 2, 2018 20:34
-
-
Save janvanderhaegen/8301294 to your computer and use it in GitHub Desktop.
Keep your site hot
This file contains hidden or 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 CheckMySite() { | |
//Thanks to Sandrino Di Mattia: http://fabriccontroller.net/blog/posts/job-scheduling-in-windows-azure/ | |
warmUpSite("https://mysite.azurewebsites.net/HTMLClient/default.htm"); | |
warmUpSite("https://mysecondsite.azurewebsites.net/HTMLClient/default.htm"); | |
} | |
function warmUpSite(url) { | |
var currentdate = new Date(); | |
//Poor man's time zone conversion to Central Time | |
currentdate.setHours(currentdate.getHours() - 6); | |
//Three cheers for JS date formatting | |
var datetime = "" + (currentdate.getMonth() +1) + "/" | |
+ currentdate.getDate() + "/" | |
+ currentdate.getFullYear() + " @ " | |
+ currentdate.getHours() + ":" | |
+ currentdate.getMinutes() + ":" | |
+ currentdate.getSeconds(); | |
if( currentdate.getHours() >= 7 || currentdate.getHours() < 19) | |
{ | |
var req = require('request'); | |
req.get({ url: url }, function(error, response, body) { | |
if (!error) { | |
console.info(datetime + " Ok"); | |
} else { | |
console.error(datetime + 'error warming up ' + url + ': ' + error); | |
} | |
}); | |
} | |
else | |
{ | |
console.info("Not within office hours " + currentdate.getHours()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment