Rails 3: Return large amount of data to user via API

蓝咒 提交于 2019-12-06 06:35:06

Heroku has a 30 second timeout, which is why your requests are failing (Probably H12 or H13 in your heroku logs).

There are three methods to work around this.

  1. Keep the connection open by sending blank data. You'll need to respond within the first 30 seconds and every 55 seconds after that. Use the time in between to process the data. Sending spaces should not affect the ability of the browser to read the response.

  2. Callback Have the user provide a callback URL in the initial request. When you finish processing the data, hit the callback url with your response.

  3. Polling As suggested by Codeglot, you can provide the user with a key. To check on their request, they can ping your server with that key.

Tell the user that their data is being processed and will be available shortly. Youtube, Vimeo, Facebook, Twitter, they all do this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!