Skip to content

Instantly share code, notes, and snippets.

@defunkt
Forked from pauldix/gist:212062
Created October 16, 2009 21:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save defunkt/212071 to your computer and use it in GitHub Desktop.
Save defunkt/212071 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'typhoeus'
require 'yajl/json_gem'
hydra = Typhoeus::Hydra.new
request = Typhoeus::Request.new('http://localhost:8089/?id=timeline', :method => :post, :body => stuff.to_json)
request.on_complete do |response|
response.code # http status
response.body
response.time # time taken in seconds
response.headers # string
end
hydra.queue(request)
hydra.run
# now again
def queue_request(hydra, stuff_queue)
next_hook = stuff_queue.pop
request = Typhoeus::Request.new(next_hook.uri, :method => :post, :body => next_hook.body.to_json)
request.on_complete do |response|
response.code # http status
response.body
response.time # time taken in seconds
response.headers # string
while !stuff_queue.empty? do
queue_request(hydra, stuff_queue) unless stuff_queue.empty?
end
end
hydra.queue(request)
end
stuff_queue # an array or IO object of a lot of stuff
40.times do
queue_request(hydra, stuff_queue) unless stuff_queue.empty?
end
hydra.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment