Skip to content

Instantly share code, notes, and snippets.

@janvanderhaegen
Last active May 2, 2018 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janvanderhaegen/8301294 to your computer and use it in GitHub Desktop.
Save janvanderhaegen/8301294 to your computer and use it in GitHub Desktop.
Keep your site hot
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