Class: FeedProcessor::Parser
- Inherits:
-
Object
- Object
- FeedProcessor::Parser
- Defined in:
- lib/feed_processor/parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
9 10 11 12 13 |
# File 'lib/feed_processor/parser.rb', line 9 def initialize(={}) = @feed_handler = [:feed_handler] || FeedProcessor::MongoFeedHandler.new setup_mongo([:mongo]) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/feed_processor/parser.rb', line 7 def end |
Instance Method Details
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/feed_processor/parser.rb', line 14 def execute queue = Beanstalk::Pool.new(['localhost:11300']) puts "Now accepting feeds to parse..." begin loop do job = queue.reserve if job.body =~ /^START (.+)$/ puts "starting #{$1} feeds" elsif job.body =~ /^END (.+)$/ puts "finished #{$1} feeds" else url = job.body puts "parsing #{url}" responses = Response.all(:conditions => {'url' => url}) responses.each do |response| begin feed = Feedzirra::Feed.parse(response.data) @feed_handler.process(url, feed) rescue => e puts "error parsing feed #{url}: #{e.message}" end end end job.delete end rescue Interrupt puts "Exiting parser" end end |