Skip to content

Instantly share code, notes, and snippets.

@3dd13
Created April 22, 2010 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3dd13/375001 to your computer and use it in GitHub Desktop.
Save 3dd13/375001 to your computer and use it in GitHub Desktop.
example of using Typhoeus
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