dstrelau (owner)

Revisions

gist: 227472 Download_button fork
public
Public Clone URL: git://gist.github.com/227472.git
Embed All Files: show embed
cache_warmer.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env ruby
require 'typhoeus'
 
HOST = 'http://yourhost.com'
CONCURRENTS = 5
 
urls = File.readlines(ARGV.shift)
hydra = Typhoeus::Hydra.new
 
queue_req = lambda do |resp|
  return if urls == []
  url = HOST + urls.pop
  puts "Processing: #{url}"
  req = Typhoeus::Request.new(url)
  req.on_complete(&queue_req)
  hydra.queue(req)
end
 
CONCURRENTS.times { queue_req.call(0) }
 
hydra.run