如何在 Rails 控制器中使用 EventMachine(superfeeder-ruby gem)?

发布于 2024-12-11 01:43:20 字数 560 浏览 0 评论 0原文

感谢您查看此内容。

不幸的是,我是 Rails 新手。我目前必须实现 Superfeedr 可以将更新推送到的端点,但该端点必须位于 Rails 控制器中。

最初,在我看来,这应该是一个运行的后台作业,网络的其他部分也倾向于同意,但我被迫将其包含为 Rails 控制器 - 这让我感到困惑。我不确定如何将 EventMachine 包含在请求/响应周期中。

我知道网络上充满了示例,但没有一个真正回答我如何路由的问题。我不知道。

我有一个名为 Superfeeds 的 Rails 控制器。我希望 Superfeeder 将更新推送到 myrailsapp/superfeeds/ 等

内部提要中,我想检查推送的内容,然后将其结果写入另一个实际具有模型的控制器并将其保留。

基本上,称为 Feeds 的控制器只需要接收并传递信息。然而,这让我感到困惑,因为它似乎必须在 Rails 控制器内实现一些长期运行的过程 - 我什至不确定这是否可行。

有谁知道使用 Rails 完成此操作但不使用 EventMachine 作为后台作业的方法吗?最后我真的只需要知道这是可能的。

-L

thank you for taking a look at this.

I am new to rails, unfortunately. I currently have to implement an endpoint that Superfeedr can push updates to, but that endpoint has to be in a rails controller.

Initially it seemed to me that this should be a background job that runs and the rest of the web tends to agree, but I am being pressured to include this as a rails controller - which confuses me. I am not certain how to include EventMachine in a request/response cycle.

I know the web is full of examples, but none really answer my question with how to route this. I have no idea.

I have a rails controller, called Superfeeds. I want Superfeeder to push updates to something like myrailsapp/superfeeds/

Inside feeds I want to inspect the pushed content, and then write the results of that to another controller that actually has a model and will persist it.

Basically, the controller called Feeds just needs to receive and pass the information along. This confuses me however because it seems to have to implement something which is a long running process inside of a rails controller - and I am not even sure if this can work.

Does anyone know of a way that this has been done with rails, but not using EventMachine as a background job? In the end I really just need to know that this is possible.

-L

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眼眸 2024-12-18 01:43:20

在提要内部,我想检查推送的内容,然后将结果写入另一个实际具有模型并将其保留的控制器。

为什么不在一个控制器中完成所有工作呢?如果您试图分离出不同的关注点,您甚至可以使用两种模型 - 例如,一种用于执行检查/解析,另一种用于处理持久化。但您很少需要或想要将数据从一个控制器传递到另一个控制器。

我不确定如何将 EventMachine 包含在请求/响应周期中。

我自己从未使用过 superfeedr,但快速浏览了文档 - 您使用的是 XMPP 还是 PubSubHubbBub 客户端?我认为是后者?如果是这样,您想要异步执行持久化(以及任何其他耗时的过程)(请求/响应周期之外),对吗?

如果您使用基于 EventMachine 的 Web 服务器(例如 Thin),则基本上每个请求周期都在 EM 反应器内运行。因此,您可以利用 EM 的设施来卸载任务,例如延迟线程池。有关此操作的示例,请查看 Enigmamachine,特别是 此处。 (我相信此外您的数据库客户端库需要异步。)

Inside feeds I want to inspect the pushed content, and then write the results of that to another controller that actually has a model and will persist it.

Why not do all the work in the one controller? If you're trying to separate out different concerns, you could even use two models - for instance one to do the inspecting/parsing and one to handle the persisting. But rarely would you need or want to to pass data from controller to controller.

I am not certain how to include EventMachine in a request/response cycle.

Never used superfeedr myself, but glanced at the docs quickly - are you using the XMPP or PubSubHubbBub client? I assume the latter? If so, you want to do the persistence (and any other time-consuming process) async (outside the request/resp cycle), right?

If you are using an EventMachine-based webserver such as Thin, basically every request cycle is run within an EM reactor. So you can make use of EM's facilities for offloading tasks such as the deferred thread pool. For an example of this in action, check out Enigmamachine, in particular here. (I believe that in addition your db client library needs to be asynchronous.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文