Question

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

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top