Reputation: 131
I have a rails 4 application which has some API methods and those methods consumes time for computation and generating huge JSON response for clients. The problem is that these requests block the entire app. And only one 1 user(request) can be served at the same time. The request runs for a long time to generate JSON response. When the first request is running, and the application receives new request's then all those new request's are failed.. How to solve this.. Unfortunately rails doesn't this automatically.. I have gone through similar threads on SO, but was not able to find solution for Rails 4 application.Please share your experience and guide me in the right direction to solve this issue. Thanks!
Upvotes: 0
Views: 1238
Reputation: 61
The best practice for such long running API calls is to make them asynchronous. That way the user thread is not blocked.
The two popular gems to run background jobs are
1) https://github.com/collectiveidea/delayed_job
2) https://github.com/resque/resque
Upvotes: 1