Created
April 10, 2014 21:03
-
-
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.
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
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