Skip to content

Instantly share code, notes, and snippets.

@itsderek23
Created April 10, 2014 21:03
Show Gist options
  • Save itsderek23/10423198 to your computer and use it in GitHub Desktop.
Save itsderek23/10423198 to your computer and use it in GitHub Desktop.
Run the desired command, ping Deadman's Snitch when completed, report to Sentry on exception.
module MonitoredJob
def self.run(command, ping_url)
eval(command)
self.ping_twice(ping_url)
return "SUCCESS"
rescue => e
Raven.capture_exception(e)
return "'#{command}' could not run: #{e.message}\n#{e.backtrace}"
end
def self.ping_twice(ping_url)
uri = URI.parse(ping_url)
http = Net::HTTP.new(uri.host,uri.port)
if uri.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
begin
self.ping_with_timeout(http, uri.request_uri)
rescue Timeout::Error, EOFError
self.ping_with_timeout(http, uri.request_uri)
end
end
def self.ping_with_timeout(http, request_uri)
Timeout::timeout(WEB_SERVICE_TIMEOUT) do
http.get(request_uri)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment