Created
April 22, 2010 09:00
-
-
Save 3dd13/375001 to your computer and use it in GitHub Desktop.
example of using Typhoeus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main | |
# urls is a hash containing url to retrieve statuses of items | |
get_csv(urls, items) { |response, item| | |
item_results = CSV.parse_line(response.body) | |
item.setStatus(item_results[0]) | |
} | |
end | |
def process_response(urls, items) | |
hydra = Typhoeus::Hydra.new(:max_concurrency => 50) | |
request_pool = Array.new | |
items.each { |item| | |
request = Typhoeus::Request.new(urls[item.id]) | |
request.on_complete do |response| | |
yield(response,item) | |
end | |
request_pool << request | |
end | |
} | |
request_pool.each{ |request| hydra.queue request} | |
hydra.run | |
request_pool.each{ |request| request.handled_response} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment