Heroku 上的后台作业网络如何知道它已完成
因此,我正在创建这个应用程序,有时它需要提取提要,并且由于 xml 解析器需要时间,它在 Heroku 上总是超时。所以,我改为每次加载页面时都通过Ajax异步加载。我的 Ajax 调用仍然收到 H12 错误。现在我正在考虑使用 Resque 在后台运行该作业。我可以做到这一点,没有问题,但我如何知道工作已完成,以便我可以通过 AJAX 将处理后的提要拉到 html 页面上?
不确定我的问题是否清楚,那么 Web 层如何知道工作已完成并且应该发出信号(例如 JavaScript 中的 onComplete)来填充页面上的内容?
So, I'm creating this application that sometime it require pulling the feed and it's always timeout on heroku because of the xml parser takes time. So, I change to be asynchronous load via Ajax every time the page is loaded. I still get H12 error from my Ajax call. Now I'm thinking of using Resque to run the job in background. I can do that no problem but how would I know that the job is finished so I can pull the processed feed on to the html page via AJAX?
Not sure if my question is clear, so how would the web layer knows that the job is done and it should signal e.g (onComplete in javascript) to populate the content on the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以做到这一点
JavaScript 可以使用 AJAX 来轮询服务器以获取结果,服务器可以用“尚未”或结果进行响应。您不断询问,直到获得结果。
您可以看看 Juggernaut (http://juggernaut.rubyforge.org/),其中让你的服务器推送到客户端
Web Sockets 是处理该问题的 HTML5 方式。有一些实用工具可以帮助您入门最佳 Ruby on Rails WebSocket 工具
There are a number of ways to do this
The JavaScript can use AJAX to poll the server asking for the results and the server can respond with 'not yet' or the results. You keep asking until you get the results.
You could take a look at Juggernaut (http://juggernaut.rubyforge.org/) which lets your server push to the client
Web Sockets are the HTML5 way to deal with the problem. There are a few gems around to get you started Best Ruby on Rails WebSocket tool
你这里有一个架构问题。 H12 的原因是为了让用户坐在那里的时间不会超过 30 秒。
通过将长时间运行的任务移入 Resque 队列,您将使其与前端 Web 进程断开连接 - 由于进程隔离,两者无法进行通信。
因此,你需要看看你在做什么以及如何做。例如,如果您正在提取提要,您是否能够在用户需要查看输出并以某种方式缓存结果之前的某个时刻执行此操作 - 或者您是否能够从用户那里获取提要请求并然后当你有数据供他们查看时,给他们发电子邮件等等。
你这里遇到的问题是,你的用户要求的东西需要比合理的时间更长的时间才能完成,因此你需要仔细看看你在做什么以及如何做。
You have an architecture problem here. The reason for the H12 is so that the user is not sat there for more than 30 seconds.
By moving the long running task into a Resque queue, you are making it disconnected to the front end web process - there is no way that the two can communicate due to process isolation.
Therefore you need to look at what you are doing and how. For instance, if you are pulling a feed, are you able to do this at some point before the user needs to see the output and cache the results in some way - or are you able to take the request for the feed from the user and then email them when you have the data for them to look at etc etc.
The problem you have here is that your users are asking for something which takes longer than a reasonable amount of time to complete, so therefore you need to have a good look at what you are doing and how.