Sha256: 0594e2d3f8f0b1e9c3e2f5adecf1e63b1c69b1fe9a1bc94a5bd84c53f0bebce6

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

class Roda
  module RodaPlugins
    # The heartbeat handles heartbeat/status requests.  If a request for
    # the heartbeat path comes in, a 200 response with a
    # text/plain Content-Type and a body of "OK" will be returned.
    # The default heartbeat path is "/heartbeat", so to use that:
    #
    #   plugin :heartbeat
    #
    # You can also specify a custom heartbeat path:
    #
    #   plugin :heartbeat, :path=>'/status'
    module Heartbeat
      OPTS = {}.freeze
      PATH_INFO = 'PATH_INFO'.freeze
      HEARTBEAT_RESPONSE = [200, {'Content-Type'=>'text/plain'}.freeze, ['OK'.freeze].freeze].freeze

      # Set the heartbeat path to the given path.
      def self.configure(app, opts=OPTS)
        app.opts[:heartbeat_path] = (opts[:path] || app.opts[:heartbeat_path] || "/heartbeat").dup.freeze
      end

      module InstanceMethods
        # If the request is for a heartbeat path, return the heartbeat response.
        def call
          if env[PATH_INFO] == opts[:heartbeat_path]
            response = HEARTBEAT_RESPONSE.dup
            response[1] = Hash[response[1]]
            response
          else
            super
          end
        end
      end
    end

    register_plugin(:heartbeat, Heartbeat)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
roda-2.9.0 lib/roda/plugins/heartbeat.rb
roda-2.8.0 lib/roda/plugins/heartbeat.rb
roda-2.7.0 lib/roda/plugins/heartbeat.rb
roda-2.6.0 lib/roda/plugins/heartbeat.rb
roda-2.5.1 lib/roda/plugins/heartbeat.rb
roda-2.5.0 lib/roda/plugins/heartbeat.rb
roda-2.4.0 lib/roda/plugins/heartbeat.rb
roda-2.3.0 lib/roda/plugins/heartbeat.rb