Created
November 25, 2012 02:57
-
-
Save mcfadden/4142202 to your computer and use it in GitHub Desktop.
Heroku app pinger
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
# requires "heroku-api" gem | |
require 'open-uri' | |
require 'net/http' | |
# Shorten timeout in Net::HTTP | |
module Net | |
class HTTP | |
alias old_initialize initialize | |
def initialize(*args) | |
old_initialize(*args) | |
@read_timeout = 5 # 5 seconds | |
end | |
end | |
end | |
namespace :ping do | |
task :go do | |
API_KEY = "000000000000000000" | |
puts "Connecting to Heroku API" | |
heroku = Heroku::API.new(api_key: API_KEY) | |
apps = heroku.get_apps.body | |
apps.each do |app| | |
open_url app | |
end | |
puts "\n\nCompleted pings" | |
end | |
end | |
def open_url(app) | |
print "\nopening #{app["name"]}".ljust(40, '.') | |
begin | |
open(app["web_url"].gsub(/^https?\:\/\//, 'https://')) | |
print "success" | |
rescue OpenURI::HTTPError => the_error | |
print "error: #{the_error}" | |
rescue OpenURI::HTTPRedirect => the_error | |
print "redirect: #{the_error}" | |
rescue => error | |
print "Failed to open #{app["web_url"]}" | |
print " ... #{error}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment