Sha256: 44802fe9b390e9772c7709d9ea8d865eed83e23a963c28375274d3eb3162b155

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

# frozen-string-literal: true

#
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
      # 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
        private

        # If the request is for a heartbeat path, return the heartbeat response.
        def _roda_before_20__heartbeat
          if env['PATH_INFO'] == opts[:heartbeat_path]
            response = @_response
            response.status = 200
            response['Content-Type'] = 'text/plain'
            response.write 'OK'
            throw :halt, response.finish
          end
        end
      end
    end

    register_plugin(:heartbeat, Heartbeat)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
roda-3.69.0 lib/roda/plugins/heartbeat.rb
roda-3.68.0 lib/roda/plugins/heartbeat.rb
roda-3.67.0 lib/roda/plugins/heartbeat.rb
roda-3.66.0 lib/roda/plugins/heartbeat.rb
roda-3.65.0 lib/roda/plugins/heartbeat.rb
roda-3.64.0 lib/roda/plugins/heartbeat.rb
roda-3.63.0 lib/roda/plugins/heartbeat.rb
roda-3.62.0 lib/roda/plugins/heartbeat.rb
roda-3.61.0 lib/roda/plugins/heartbeat.rb
roda-3.60.0 lib/roda/plugins/heartbeat.rb
roda-3.59.0 lib/roda/plugins/heartbeat.rb
roda-3.58.0 lib/roda/plugins/heartbeat.rb