Created
September 20, 2014 09:14
-
-
Save mwerner/d7601ff48b937cf602e7 to your computer and use it in GitHub Desktop.
Deploy Verifier Example
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 'typhoeus' | |
class DeployVerifier | |
def self.verify(asset_paths) | |
urls = asset_urls(asset_paths) | |
return 'No assets found' if urls.empty? | |
verify_urls(urls.uniq, &blk) | |
end | |
private | |
def self.verify_urls(urls) | |
hydra = Typhoeus::Hydra.hydra | |
errors = [] | |
urls.each do |link| | |
request = Typhoeus::Request.new(link, method: "HEAD") | |
request.on_complete do |response| | |
if response.success? | |
yield response.request.url, response.success?, nil if block_given? | |
else | |
error = interpret_failure(response) | |
yield response.request.url, response.success?, error if block_given? | |
errors << {link: link, error: error} | |
end | |
end | |
hydra.queue request | |
end | |
hydra.run #blocks | |
errors | |
end | |
end | |
errors = DeployVerifier.verify(['assets/script-abc123.js','assets/styles-def987.css']) | |
if errors.any? | |
puts "Assets unavailable:" | |
puts errors.join("\n") | |
abort "Assets not available. Stopping deploy" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment