defunkt (owner)

Fork Of

Revisions

gist: 212071 Download_button fork
public
Public Clone URL: git://gist.github.com/212071.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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