Skip to content

Instantly share code, notes, and snippets.

@theoperatore
Created May 8, 2015 04:43
Show Gist options
  • Save theoperatore/e483cdaa86fc891ebf8f to your computer and use it in GitHub Desktop.
Save theoperatore/e483cdaa86fc891ebf8f to your computer and use it in GitHub Desktop.
Ping a Heroku web app to keep it from sleeping.
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