Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

RESTful polling #158

wants to merge 3 commits into from

Conversation

slef
Copy link

@slef slef commented Feb 3, 2014

Added a RestPollingAgent that (repeatedly) polls a URL and creates an event whenever the server responds.

bin/schedule.rb Outdated
active_agents = Set.new
EM.run do
EM.add_periodic_timer(10) {
Agent.find_each do |agent|
Copy link
Member

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?

Copy link
Author

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.

@cantino
Copy link
Member

cantino commented Feb 3, 2014

Thanks @slef, I left some comments. Looks like a good step forward! Can you add some specs?

@cantino
Copy link
Member

cantino commented Feb 17, 2014

How's it going?

Added deactivation of destroyed continuous agents in EM. Handling http
and parsing errors in RestPollingAgent.
@slef
Copy link
Author

slef commented Feb 20, 2014

The update should handle the destruction of agents, and does some error handling.
I'll try to add specs soon.

Gemfile Outdated
@@ -36,6 +36,7 @@ gem "twitter"
gem 'twitter-stream', '>=0.1.16'
gem 'em-http-request'
gem 'weibo_2'
gem 'cobravsmongoose'
Copy link
Member

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?

Copy link
Author

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?

Copy link
Member

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
.

@slef
Copy link
Author

slef commented Feb 21, 2014

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
In particular in my application, I need to access attributes, which are lost in simpler solutions such as Hash.from_xml(s).to_json
If we don't want to use an already existing converter, the alternatives are:

  • rewrite one from scratch -- should take about a page of code, same as the existing gems
  • save the raw XML in the payload and create another agent to extract information from there (like formatting agent but for XML)
  • add some more options to extract the relevant information directly
    What do you think is best?

@cantino
Copy link
Member

cantino commented Feb 21, 2014

Okay, let's use badgerfish.

On Thu, Feb 20, 2014 at 11:11 PM, slef notifications@github.com wrote:

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
In particular in my application, I need to access attributes, which are
lost in simpler solutions such as Hash.from_xml(s).to_json
If we don't want to use an already existing converter, the alternatives
are:

  • rewrite one from scratch -- should take about a page of code, same
    as the existing gems
  • save the raw XML in the payload and create another agent to extract
    information from there (like formatting agent but for XML)
  • add some more options to extract the relevant information directly
    What do you think is best?

Reply to this email directly or view it on GitHubhttps://github.com//pull/158#issuecomment-35704326
.

@slef
Copy link
Author

slef commented Feb 21, 2014

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be error?

Copy link
Author

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.

@cantino
Copy link
Member

cantino commented Feb 23, 2014

Thanks @slef. Can you add some specs for your new behavior?

@slef
Copy link
Author

slef commented Mar 6, 2014

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.
If I do this, and em-start an agent, how do I check that the event was created?

@cantino
Copy link
Member

cantino commented Mar 7, 2014

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.

@0xdevalias
Copy link
Member

@slef Did you ever figure out a nice way to write specs for this?

@slef
Copy link
Author

slef commented Jun 2, 2014

Not really... I'll try to get back to this within a couple of weeks. Any ideas?

@slef slef mentioned this pull request Jun 2, 2014
@0xdevalias
Copy link
Member

Unfortunately not off hand. Specs are my downfall as well :P

@cantino
Copy link
Member

cantino commented Jun 2, 2014

@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?

@slef
Copy link
Author

slef commented Jun 3, 2014

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 continuous!.
And if we can find a way to make scheduling accurate in EM, then we could put everything in there. Right?

@dsander
Copy link
Collaborator

dsander commented Jun 3, 2014

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.
I however still believe the EM loop should be run in a separate process (or thread with the threaded workers).

@cantino cantino mentioned this pull request Aug 21, 2014
@Jngai
Copy link
Contributor

Jngai commented Apr 6, 2016

@slef are you still working on this? looks like its almost done minus the spec.

@slef
Copy link
Author

slef commented Apr 19, 2016

I have taken a break for a while. Feel free to take a shot at it if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants