class BarsoomUtils::PingHealthCheck

Public Instance Methods

call() click to toggle source
# File lib/barsoom_utils/ping_health_check.rb, line 10
def call
  return unless ENV["ENABLE_HEALTH_CHECKS"]

  response = ping_healthcheck

  if response.code != 200
    # "The presence of the cf-request-id header in the response confirms
    # the request was proxied through Cloudflare"
    #   https://support.cloudflare.com/hc/en-us/articles/203118044-Gathering-information-for-troubleshooting-sites
    raise "Bad response, cf-request-id header: #{response.headers["cf-request-id"]}, response body: #{response.inspect}"
  else
    response
  end
rescue => ex
  BarsoomUtils::ExceptionNotifier.message("Couldn't report to healthchecks.io, maybe the service is down?", "Check: #{id}, Error: #{ex.inspect}")
end

Private Instance Methods

ping_healthcheck() click to toggle source
# File lib/barsoom_utils/ping_health_check.rb, line 29
def ping_healthcheck
  HTTParty.get("https://hchk.io/#{id}")
end