Search code examples
ruby-on-rails-3.1uploadherokuhttp-streamingpooling

HTTP streaming on Heroku (upload lots of data)


I have one app hosted on Heroku and this app saving lots of data information to database (it takes about 70 seconds).

Heroku after 30 seconds period of every request display the error page H12 about timeout, how could I display some info-message while the upload is in progress instead of displaying H12 error?

I have been looking for some example of this, but I wasn't much successful... I just found some notes, that I have to send every time (eg. 15 seconds) some control string from server, but I already didn't find some specific example how to do that...

Any advices how to do that?

Thank in advance.


Solution

  • It is a poor practice to have your users wait for 70 seconds for a request to complete on any platform. Heroku just enforces this best practice by implementing the 30-second timeout. So the real question is how to better architect the application.

    Heroku has an article on implementing background workers which are designed to solve this very problem: https://devcenter.heroku.com/articles/queueing

    The basic approach is to have the web request schedule a background job (using Delayed Job, Queue Classic, Resque etc...) and immediately respond to the user with some indicator of progress. Then a dyno running a background worker does the heavy lifting of saving the info to the db. When it's done it flips some flag in a db or other storage mechanism which notifies to the web client that the job is now complete.

    Running a background worker does require another dyno. If you're looking to avoid that expense you can look into Girl Friday which many report having success with.

    Hope that helps.