Skip to content

Instantly share code, notes, and snippets.

@mcfadden
Created November 25, 2012 02:57
Show Gist options
  • Save mcfadden/4142202 to your computer and use it in GitHub Desktop.
Save mcfadden/4142202 to your computer and use it in GitHub Desktop.
Heroku app pinger
# 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