How to efficiently implement a blocking call with Rails, while letting the client wait for the reply
- by Kyle Heironimus
We have a web service written in Rails. The API is published and we cannot change it. Our app communicates with a remote web service that sometimes hangs or takes several seconds to reply.
Client -> Our Web Service -> Remote Web Service
Currently, if the remote web service hangs for 5 seconds, one of our rails processes on our web service also hangs with it, which is what we need to avoid.
I've seen things such as mod-x-sendfile, modporter, and delayed jobs, but the best I can tell, they all assume the client is not waiting for an answer. Since the API is already established, we cannot tell the client "I'm attempting to do what you want, check back later for the answer."
The best option we have come up with so far is to add a second, non-rails web server running eventmachine to process these particular calls. Is there a better way?