I have a method in my rails app that makes about a 1000 REST calls. Unfortunately, it crashed pretty quickly because of a timeout:
Error H12 (Request timeout) -> POST MyApp.herokuapp.com/expensiveCall dyno=web.1 queue= wait= service=30000ms status=503
How do I avoid this timeout? Should I be careful of anything along these lines? (Making this call is pretty costly – so looking for things I should avoid).
Thanks!
Edit
Also, would it be a good idea to launch a thread that would make those 1000 REST calls rather having the request wait for completion. If so, how could I do that?
You’re going to need to put this into a background job of some sort. You can use something like delayed_job, or resque. Delayed Job is tool that you can use in rails to create a job that can be performed at another time, or put into a queue. Delayed Job has a fairly similar interfance in some respects to that of active record. Checkout the readme on the link there for setting it up. I’ve heard good things about resque which also allows you to do that, but I have no experience in using it.