Uw betrouwbare partner voor (mobiele) web applicaties
TwitterEmailRSS

Prevent your Heroku Play! apps from idling

Disclaimer: we understand that the following may be a teeny weeny bit disrespectful to the free service Heroku provides, but asking $35/month is a bit steep for a website with less than 24 requests per day. If it gets popular some day, we will ofcourse reconsider our strategy.

While looking for a cloudservice to host our libwat.ch Play! (Java) app, we stumbled upon Heroku.com. It’s a really nice service which supports all kinds of (free and paid) configurations.

Cheap Dutch basterds as we are, we wanted the free service -so that means 1 webworker which falls asleep after an hour of inactivity. The app isn’t that popular yet (c’mon, sign up!), so it dozes off very frequently.

This means the request (person) that awakes the app must wait some 20 seconds while the app steps out of bed, brushes its teeth and combs its hair… not good!

Fortunately, only the webworker is put to sleep, so any background jobs are never idled, which leaves us with a nice opportunity to insomnatise the webworker 🙂

Just add this job to your Play app* :

@Every("55min")
public class KeepSiteAwakeJob extends Job {

  @Override
  public void doJob() throws IOException {
    new URL("http://libwat.ch").getContent();
  }

}

*) Note that if you’re not using Play!, you could still use one of the free scheduler plugins Heroku offers and have that invoke the website every sub-60 minutes.