-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RESTful polling #52
Comments
Interesting! Which direction would this be polling? So the Agent would open up a URL and provide a long-polling endpoint for another service? Or it would subscribe to a long-polling endpoint and wait for events? |
What I would like for my application is to have the huginn agent subscribe to a long polling endpoint. This way, it could instantly create events when it is notified of changes in my lights, blinds or temperature. If I understood the procedure correctly, the (e.g. Huginn) agent sends a HTTP GET request to the server (e.g. openremote) and the server only responds whenever a status change occurs, at which point it sends the new information in JSON or XML format. If no change occurs within a prescribed amount of time, the server timeouts. There is also the option of getting the current status of a sensor with a GET request to a different url, or to POST to a switch (e.g. to turn on the light etc). This would allow for example to turn off all the lights when I leave from home etc. |
That's totally achievable. Right now the only Agent that runs a continuous On Sun, May 12, 2013 at 2:54 PM, slef notifications@github.com wrote:
|
Is this something you'd like to work on? |
I would, but this week will be a bit busy for me. If someone else is eager to get it done, please go ahead, otherwise I will try to do it whenever I find some time. |
It'd be great if you want to take crack at it. The primary code for the Twitter Agent is run by |
Maybe the right model is to allow any Agent to be declared |
Yes that sounds reasonable. |
I just looked at the code of Huginn and EventMachine. If I understood correctly, Huginn propagates events every 5m and in between nothing happens. It this correct? |
That's correct for the scheduler, but if you look at the On Sun, Jun 2, 2013 at 9:22 AM, slef notifications@github.com wrote:
|
I see how to use EM to maintain network connections, but I can't find anything on managing internal events. Do we have to create a new connection class? |
To clarify, are you referring to a possible internal EM handler for Huginn events? Or do you mean for consuming an external stream and creating Huginn events? |
Yes, I was referring to possible internam EM handler for Huginn events (of both actually). Looking at EM, it looks like only scheduled or I/O events are managed (the main loop runs select* on file descriptors). Is this correct or is there some way to trigger EM connections that I do not see? Although if we want to do that, we should probably think of some mechanism to avoid creating loops that might hog the system. |
Ah ok, it seems like this is doable just using EM:Queue to queue the processing of events that have been created. This seems to be a pretty fundamental change to the main loop of Huginn. I have no time to look at it further right now, I'll try again if I can find some time in a week or so. |
I finally found some time to get back to this (added a pull request with the resulting changes). |
Cool! Interesting timing on the discussion. See #157 |
@slef's approach of using EventMachine will still be faster than our current system, as you could get data into Huginn from a remote source in the sub-second range. Right now Agents don't run more often than once a minute. It would be a pretty big change to how Huginn works, though, I think. |
I think we should add a way to support "long running" agents at some point. Long polling is one use case, webhooks, chat (IRC) consumers are a few others which would be nice to have. I though about this a little over the weekend and might add some basic "framework" to support this over the next week. |
Actually if you look at my code in #158, I added an EM to |
Does Rails work okay when inside an EM loop? What happens if you have two workers (like Unicorn instances)? Or should the EM loop be in a separate process? |
I do not think the EM loop will cause any problems with rails it is run in the same process (or thread with the threaded workers #318) as the scheduler, so it should not make a difference how many unicorn instances are running. |
As far as I understand it, in the current |
Can you run multiple EM loops? @dsander What do you think of how this is setup now? |
@slef I also think rufus spawns a worker thread to run the scheduled events, but the problem is that the GIL (at least for the MRI) will block all other threads for the time ruby code is executed. I would like to have it as a separate module/class and a small wrapper to run it (like we have for the scheduler, twitter stream, etc) and add it to the threaded worker by default. @cantino I think you can run multiple event loops if you run them in separate threads, but I have never done that |
@dsander I agree that we should make it separate, but run together by default, as you described. |
It would be great to have a RESTful agent capable of long polling.
This would, for example, allow me to have huginn watch lights turn on and off in my house using the openremote rest API
http://www.openremote.org/display/docs/Controller+2.0+HTTP-REST-JSONP
I'm sure there would be many more applications.
I'm new to huginn and to Ruby but if someone can point me to parts of the code I should look at, I'm willing to give it a try.
The text was updated successfully, but these errors were encountered: