Sha256: 6660bb7bf30f01ebf3ad2a4b5035516cfed0ca479e5e73edb56d209da360e882

Contents?: true

Size: 1002 Bytes

Versions: 16

Compression:

Stored size: 1002 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://hc-ping.com/#{id}")
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
barsoom_utils-0.2.0.47 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.2.0.46 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.2.0.44 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.2.0.43 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.2.0.42 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.2.0.41 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.40 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.39 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.38 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.36 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.34 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.33 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.32 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.31 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.30 lib/barsoom_utils/ping_health_check.rb
barsoom_utils-0.1.1.29 lib/barsoom_utils/ping_health_check.rb