流、守护进程、Cronjobs,你如何使用它们? (红宝石)

发布于 2024-08-06 03:18:28 字数 652 浏览 11 评论 0原文

我终于有时间研究流媒体、守护进程和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-08-13 03:18:28

首先,如果一个网站不提供 API,那么这强烈表明解析和提取其数据是不合法的,但是您最好检查他们的使用条款和隐私政策。

就我个人而言,我不知道所谓的“Streaming API”,但假设它们有一个 API ,您仍然需要提取它提供的结果(xml,json,...),解析它们并将它们呈现回用户。该策略会根据您的应用程序类型而有所不同:

  1. 桌面应用程序:然后您可以直接提取数据,解析它并将其提供给用户,许多应用程序就像 Twhirl 一样。
  2. Web应用程序:那么您需要减少提取数据的时间。通常,您将从 API 中提取数据并存储它。然而,存储数据有点棘手!您不希望您的数据库因应用程序检索数据时的极端拉取查询而被锁定。实现此目的的一种方法是使用推送方法;在这种情况下,请按照选项 2 获取数据,然后推送给用户。如果您想要即时更新(例如聊天),您可以查看 orbited。如果可以将数据保存到某种用户和关注者的“收件箱”,那么据我所知,最简单的方法是使用 IMAP 将更新发送到用户收件箱。

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:

  1. Desktop app: then you just can pull the data directly, parse it and provide it to the user, many apps are like that just like Twhirl.
  2. Web app: then you need to cut down the time for extracting the data. Typically you will pull the data from the API and store it. However, storing the data is a bit tricky! You don't want want your database to be a lock down for the app by the extreme pull queries that it gonna get to retrieve the data back. One way to do this is to use push methodology; follow option 2 in this case to get the data and then push to the user. If you want instant updates like chat for example you can have a look at orbited. If it's ok to save the data to some kind of user and followers' 'inboxes', then the simplest way as I can tell is to use IMAP to send the updates to the user inbox.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文