流、守护进程、Cronjobs,你如何使用它们? (红宝石)
我终于有时间研究流媒体、守护进程和 cron 任务以及围绕它们构建的所有精美宝石!但我不清楚 如何/何时使用这些东西。
我有几个问题:
1) 如果我想要一个不断更新、实时的网站,其中包含我的 Facebook 好友的活动源、我最喜欢的书籍的最新亚马逊书评以及我的 Twitter 源,我是否可以使用 Daemon gem、用于流式传输内容的 ruby-yali gem 以及Whenever gem 创建一些自定义流实现,它可以说,每 3-10 秒检查这些网站,看看我正在寻找的内容是否有改变了?是这样的吗?或者通常/最好以不同的方式进行?
2) (1) 是否过于占用处理器资源?考虑到您想要实时更新的网站没有流媒体 API,是否有更好的方法来实现实时内容流?我正在考虑在一个单独的小型 ruby 应用程序(带有守护进程和 cronjobs)中每隔几秒发送一个请求,获取 json/xml 结果,使用 nokogiri 删除我不需要的东西,然后只是通过评论/书籍/帖子/等的小列表,构建更改内容的提要,并使用 Juggernaut 或其他东西将这些更改推送到某些 Rails 应用程序。那行得通吗?
我想这一切都归结为一个问题:
某些网站的最新内容的实时流式传输如何工作?你是怎么做到的? ...所以如果有人在我的网站上,他们可以实时看到刚刚发布的新消息或新书?
期待您的答复, 槊
I've finally had a second to look into streaming, daemons, and cron
tasks and all the neat gems built around them! But I'm not clear on
how/when to use these things.
I have a few questions:
1) If I wanted to have a website that stayed constantly updated, realtime, with my Facebook friends' activity feeds, up-to-the-minute Amazon book reviews on my favorite books, and my Twitter feed, would I just create some custom streaming implementation using the Daemon gem, the ruby-yali gem for streaming the content, and the Whenever gem, which could say, check those sites every 3-10 seconds to see if content I'm looking for has changed? Is that how it would work? Or is it typically/preferably done differently?
2) Is (1) too processor intensive? Is there a better way you do it, a better way for live content streaming, given that the website you want realtime updates on doesn't have a streaming api? I'm thinking about just sending a request every few seconds in a separate small ruby app (with daemons and cronjobs), getting the json/xml result, using nokogiri to remove the stuff I don't need, and then just going through the small list of comments/books/posts/etc., building a feed of what's changed, and using Juggernaut or something to push those changes to some rails app. Would that work?
I guess it all boils down to the question:
How does real-time streaming of the latest content of some website work? How do YOU do it?
...so if someone is on my site, they can see in real time the new message or new book that just came out?
Looking forward to your answers,
Lance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果一个网站不提供 API,那么这强烈表明解析和提取其数据是不合法的,但是您最好检查他们的使用条款和隐私政策。
就我个人而言,我不知道所谓的“Streaming API”,但假设它们有一个 API ,您仍然需要提取它提供的结果(xml,json,...),解析它们并将它们呈现回用户。该策略会根据您的应用程序类型而有所不同:
Well first, if a website that doesn't provide an API, then it's a strong indication that it's not legal to parse and extract their data, however you'd better check their terms of use and privacy policy.
Personally I'm not aware of something called "Streaming API", but supposing that they have an API , you still need to pull the results provided by it(xml, json, ....), parse them and present them back to the user. The strategy will vary depending on your app type: