Created
August 1, 2017 17:33
-
-
Save technicalpickles/13c71fd11812aad93ed6987a22c47c5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'bundler/setup' | |
require 'faraday' | |
require 'typhoeus' | |
require 'typhoeus/adapters/faraday' | |
require 'pry' | |
conn = Faraday.new do |faraday| | |
faraday.adapter :typhoeus | |
end | |
urls = [ | |
'https://stackoverflow.com', | |
'https://avatars1.githubusercontent.com/u/391331?v=4&s=60', | |
'https://rubygems.org', | |
'https://www.npmjs.com/' | |
] | |
results = {} | |
urls.each do |url| | |
results[url] = [] | |
end | |
count = 20 | |
print "Running #{count} checks" | |
count.times do | |
conn.in_parallel do | |
urls.each do |url| | |
results[url] << conn.get(url) | |
end | |
end | |
print "." | |
sleep 1 | |
end | |
puts | |
results.each do |url, responses| | |
failures = responses.select do |response| | |
response.env[:typhoeus_connection_failed] || response.env[:typhoeus_timed_out] | |
end | |
puts "#{url}: #{failures.size}/#{count} failures" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment