Sha256: 81a92a73a928eb336d7ea36d707ba15a6263da985b631deeec02b46c34849ec1

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

module Startback
  module Web
    #
    # Can be used to easily implement a HealthCheck web service inside a Startback
    # application.
    #
    # Examples:
    #
    #     # Returns a 204 with no body
    #     run Startback::Web::HealthCheck.new
    #
    #     # Returns a 204 with no body
    #     run Startback::Web::HealthCheck.new { nil }
    #
    #     # Returns a 200 with Ok in plain text
    #     run Startback::Web::HealthCheck.new { "Ok" }
    #
    #     # Re-raises the exception
    #     run Startback::Web::HealthCheck.new { raise "Something bad" }
    #
    # Please note that this rack app is not 100% Rack compliant, since it raises
    # any error that the block itself raises. This class aims at being backed up
    # by a Shield and/or CatchAll middleware.
    #
    # This class is not aimed at being subclassed.
    #
    class HealthCheck

      def initialize(&bl)
        @checker = bl
      end

      def call(env)
        if debug_msg = check!(env)
          [ 200, { "Content-Type" => "text/plain" }, debug_msg ]
        else
          [ 204, {}, "" ]
        end
      end

    protected

      def check!(env)
        @checker.call if @checker
      end

    end # class HealthCheck
  end # module Web
end # module Startback

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
startback-0.4.3 lib/startback/web/health_check.rb
startback-0.4.2 lib/startback/web/health_check.rb
startback-0.4.1 lib/startback/web/health_check.rb
startback-0.4.0 lib/startback/web/health_check.rb
startback-0.3.2 lib/startback/web/health_check.rb
startback-0.3.1 lib/startback/web/health_check.rb
startback-0.3.0 lib/startback/web/health_check.rb
startback-0.2.0 lib/startback/web/health_check.rb