Rails 应用程序上的轮询、Web 套接字或 Comet
我正在尝试确定为我依赖外部 API/服务的项目做某事的最佳方法,该项目需要约 2.5-4 秒的回复时间。
目前,我正在使用 javascript 在 DOM 加载后加载 api/数据,然后 jquery 更新页面上的部分内容。尽管我拥有的加载程序很漂亮,但它仍然锁定服务器进程,所以我想使用delayed_job或其他东西将其移至Heroku工作人员中?来自 API 的信息是特定于用户的,而不是 cron 作业中的信息。
我提取的数据只需要每隔几个小时更新一次,并记录在本地数据库中,所以我猜像 Pusherapp.com 提供的全面 Web 套接字会有点过大?
我倾向于使用delayed_job进行轮询并等待状态更新以确定其完整性。有人用delayed_job做过这个吗?提示或警告?
谢谢
I'm trying to determine the best way to go about doing something for a project I have where I rely on an external API/service which takes ~2.5-4 seconds for a reply.
Currently I'm using javascript to load the api/data after the DOM has loaded then jquery updates a partial on the page. Pretty as the loader I have is, it still locks up the server process, so I'd like to move it out into a Heroku worker using delayed_job or something else? And the info from the API is user specific and not something that could be in a cron job.
The data I'm pulling only needs to be updated every few hours and is recorded locally in the DB, so I'm guessing an all out web socket such as that provided by Pusherapp.com would be overkill?
I'm leaning towards polling using delayed_job and waiting for a status update to determine it's completeness. Has anyone done this with delayed_job? Hints or caveats?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你绝对可以用delayed_job做类似的事情...但最终听起来你需要一些类似cron的东西来进行调度,对吗?或者,您不能在 heroku 上使用 cron 每隔几个小时运行一次 rake 任务吗?
Yeah you can definitely do something like that with delayed_job... but ultimately it sounds like you need something cron-like for scheduling, right? Alternatively, can't you use cron on heroku to just run a rake task every couple of hours?