I recently tweeted that Heroku apps with only one dyno will go to sleep after an hour if the app doesn’t receive any traffic. More information about Heroku’s sleep policy can be found at Heroku’s blog post. In order to prevent that from happening, you just need to “ping” that app within that hour window.
Inorder to use Google Apps Scripts you first need to have a Google account and head over to your Google Drive and create a new script.
- If you are new to Google App Scripts you first need to connect the Google Apps Script App to the rest of your existing Apps. (Docs, Presentation, Spreadsheets, etc)
- After adding the Google Apps Script app, select the Create button and select the Script option. Select the “Blank Project” option.
- Within the myFunction() definition type:
- Next set the project’s trigger by selecting: Resources -> Current project’s triggers. Make sure you select Time-driven, Minutes timer and select the 15 minutes or the 30 minutes option.
- (Optional) If you want to be notified when the trigger fails select the “notifications” option and select the email address that you want to receive the notification.
- Select the “Save” button and then rename the script to something useful. (e.g. ping-appname-heroku)
- Select the “Run” button to make sure the script executes correctly.
So now whenever you go to your Heroku app, it should respond right away without that annoying spin-up time that seem to last an eternity especially when you are trying to demo your app to a potential employer.
-Update: (2013-10-08) See my new post Using New Relic Heroku Monitoring to Keep Apps Awake as I think Heroku might be blocking this method.