-
-
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 #158
base: master
Are you sure you want to change the base?
RESTful polling #158
Conversation
… the restful polling agent.
bin/schedule.rb
Outdated
active_agents = Set.new | ||
EM.run do | ||
EM.add_periodic_timer(10) { | ||
Agent.find_each do |agent| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about removing Agents that no longer exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! Good point :) I'll fix it.
Thanks @slef, I left some comments. Looks like a good step forward! Can you add some specs? |
How's it going? |
Added deactivation of destroyed continuous agents in EM. Handling http and parsing errors in RestPollingAgent.
The update should handle the destruction of agents, and does some error handling. |
Gemfile
Outdated
@@ -36,6 +36,7 @@ gem "twitter" | |||
gem 'twitter-stream', '>=0.1.16' | |||
gem 'em-http-request' | |||
gem 'weibo_2' | |||
gem 'cobravsmongoose' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CobraVsMongoose hans't been updated since 2006. Can you use a different gem, or, ideally, just standard library tools or nokogiri?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to use https://github.com/msievers/badgerfish ?
It is more recent but has less features (only does XML -> json conversion) which is ok for our purpose. I think they are both quite short and use standard libraries. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is nokogiri too much of an inconvenience?
On Thu, Feb 20, 2014 at 6:37 PM, slef notifications@github.com wrote:
In Gemfile:
@@ -36,6 +36,7 @@ gem "twitter"
gem 'twitter-stream', '>=0.1.16'
gem 'em-http-request'
gem 'weibo_2'
+gem 'cobravsmongoose'Would it be better to use https://github.com/msievers/badgerfish ?
It is more recent but has less features (only does XML -> json conversion)
which is ok for our purpose. I think they are both quite short and use
standard libraries. What do you think?Reply to this email directly or view it on GitHubhttps://github.com//pull/158/files#r9934744
.
I thought it would be convenient to store the entire XML info in the payload as a json object and then use another agent to reformat that info. The badgerFish convention seems to be the best way of doing that in a lossless manner, see http://wiki.open311.org/index.php?title=JSON_and_XML_Conversion
|
Okay, let's use badgerfish. On Thu, Feb 20, 2014 at 11:11 PM, slef notifications@github.com wrote:
|
Done. Btw it seems like Ox (used by Badgerfish) is faster than nokogiri. http://www.ohler.com/dev/xml_with_ruby/xml_with_ruby.html |
http.errback { | ||
error "Failed: #{http.error}" | ||
if !@destroyed | ||
pp "errback again "+name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This is debugging code sorry. I wanted to see when it restarts after an error (which might not need to be logged, e.g. in case of a timeout). I'll change it.
Thanks @slef. Can you add some specs for your new behavior? |
I'm having some problems figuring out how to write specs for the agent running inside the EM loop. A long polling server could be simulated using webmock and a Queue or an EM:Queue: @jsonqueue = Queue.new
stub_request(:any, 'www.jsonexample.net').to_return { |request| @jsonqueue.pop } Then the next http request should hold until I push something on the queue. |
Yea, that's tricky. I'd probably extract the interesting parts into methods on a class, test those, and then either not test, or stub, the EM stuff. |
@slef Did you ever figure out a nice way to write specs for this? |
Not really... I'll try to get back to this within a couple of weeks. Any ideas? |
Unfortunately not off hand. Specs are my downfall as well :P |
@dsander or I can probably put something together. Is this way of doing EM Agents how we want to proceed? Should all agents head in the EM direction and phase out DJ? |
I'm not sure but it looks like EM is a bit less flexible/accurate when it comes to scheduling tasks at specific times. But for all agents that generate events from other events, webhooks, streams, etc. (basically everything but cron jobs), I don't see why they shouldn't all be |
Like I state in #52 I am not the biggest fan of EM (limited to EM enabled libraries, no additional concurrency possible) but it is much easier to implement then using threads so I think it is ok to start with it. |
@slef are you still working on this? looks like its almost done minus the spec. |
I have taken a break for a while. Feel free to take a shot at it if you like. |
Added a RestPollingAgent that (repeatedly) polls a URL and creates an event whenever the server responds.