Sha256: 1d0259cacfd0597cea2f0a9a589d3ebabeffd5cfc2081a762049d18ae3456ad0

Contents?: true

Size: 998 Bytes

Versions: 22

Compression:

Stored size: 998 Bytes

Contents

# frozen_string_literal: true
require "httparty"
require "attr_extras"
require "barsoom_utils/exception_notifier"

module BarsoomUtils
  class PingHealthCheck
    method_object :id

    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

    def ping_healthcheck
      HTTParty.get("https://hchk.io/#{id}")
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
barsoom_utils-0.1.1.28 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.27 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.26 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.25 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.24 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.23 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.22 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.21 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.20 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.19 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.18 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.17 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.16 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.15 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.14 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.13 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.12 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.11 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.10 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.9 lib/barsoom_utils/ping_health_check.rb