-
-
Save defunkt/212071 to your computer and use it in GitHub Desktop.
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
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