3

I am using HTTParty gem for a Rails application (I call it Main) to send requests to a Rails API (I call it API).

One of the request can be very long, it can last 10 seconds up to 6 minutes. Today I am using timeout: 600 option which helps to go around the time-out error.

But I would prefer to have a low time-out (such a 20 seconds), and a keep-alive sent every 10 seconds by API while the job is performed.

Question: how to send keep-alive from API?

The design I have in mind is to fork two processes on API. One would perform the heavy task, and the other would send keep-alive chunks of response to the client (which is Main). Those 2 process would communicate with a semaphore. I can write the threading code easily.

The only thing I cannot figure out is how to send keep-alive. When I render from my API controller, the whole response is sent and the connection closed. The solution on the HTTP side would be to use "chunked 'Transfer-Encoding'". I need advises on how to apply this to rails.

Thanks in advance.

Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73

0 Answers0