Sha256: 9ec0dc757b5041b3df4878a738def36d07088492116b1258bceee33aeb5b9000

Contents?: true

Size: 1.24 KB

Versions: 63

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" }, Array(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

63 entries across 63 versions & 3 rubygems

Version Path
startback-1.0.3 lib/startback/web/health_check.rb
startback-1.0.2 lib/startback/web/health_check.rb
startback-1.0.1 lib/startback/web/health_check.rb
startback-1.0.0 lib/startback/web/health_check.rb
startback-0.19.4 lib/startback/web/health_check.rb
startback-0.19.3 lib/startback/web/health_check.rb
startback-0.19.1 lib/startback/web/health_check.rb
startback-0.19.0 lib/startback/web/health_check.rb
startback-0.18.2 lib/startback/web/health_check.rb
startback-0.18.1 lib/startback/web/health_check.rb
startback-0.18.0 lib/startback/web/health_check.rb
startback-0.17.4 lib/startback/web/health_check.rb
startback-0.17.3 lib/startback/web/health_check.rb
startback-0.17.2 lib/startback/web/health_check.rb
startback-0.17.1 lib/startback/web/health_check.rb
startback-0.17.0 lib/startback/web/health_check.rb
startback-0.16.0 lib/startback/web/health_check.rb
startback-0.15.5 lib/startback/web/health_check.rb
startback-0.15.4 lib/startback/web/health_check.rb
startback-0.15.3 lib/startback/web/health_check.rb