Created
May 8, 2015 04:43
-
-
Save theoperatore/e483cdaa86fc891ebf8f to your computer and use it in GitHub Desktop.
Ping a Heroku web app to keep it from sleeping.
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
var request = require('request'); | |
var CronJob = require('cron').CronJob; | |
var URL = "https://your-heroku-name-web-app.com/"; | |
var CRONTIME = "0 25,55 * * * *"; | |
var job; | |
function ping() { | |
request(URL, function(err, response, body) { | |
if (!err && response.statusCode === 200) { | |
console.log(body); | |
} | |
else { | |
console.error("Oh dear...", err); | |
} | |
}) | |
} | |
// DO THE THING! | |
(function() { | |
job = new CronJob({ | |
cronTime : CRONTIME, | |
onTick : ping, | |
start : false | |
}) | |
job.start(); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment