2

I have a Sinatra app that looks something like this:

get '/generate'
  generate_result(params) # method that takes several minutes to complete
end

Unfortunately, method 'generate_result' takes several minutes to run. But Heroku's limitation is 30 seconds per request. I'm using a free Heroku account, so I'm looking for a solution that doesn't require buying a worker dyno.

I tried 'rack-timeout' gem, but the problem still appears on Heroku.

Sergey
  • 47,222
  • 25
  • 87
  • 129

1 Answers1

2

In order to support web sockets and long polling, Heroku provides a way around the timeout. Upon the initial request, you have 30 seconds to respond to the client with at least one byte, after which each subsequent byte will keep the connection open for at least 55 seconds.

https://devcenter.heroku.com/articles/request-timeout#long-polling-and-streaming-responses

As a hack, you can thus repeatedly send "heartbeat" messages over the connection in order to keep it alive. The remaining question is whether it's worth it – usually you'd be better off by doing background processing.

Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168