Module: HttpHealthCheck

Defined in:
lib/http_health_check.rb,
lib/http_health_check/probe.rb,
lib/http_health_check/utils.rb,
lib/http_health_check/probes.rb,
lib/http_health_check/version.rb,
lib/http_health_check/rack_app.rb,
lib/http_health_check/config/dsl.rb,
lib/http_health_check/probe/result.rb,
lib/http_health_check/utils/karafka.rb,
lib/http_health_check/probes/sidekiq.rb,
lib/http_health_check/probes/ruby_kafka.rb,
lib/http_health_check/probes/delayed_job.rb

Defined Under Namespace

Modules: Config, Probe, Probes, Utils Classes: ConfigurationError, Error, RackApp

Constant Summary collapse

VERSION =
'0.5.0'

Class Method Summary collapse

Class Method Details

.add_builtin_probes(conf) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/http_health_check.rb', line 25

def self.add_builtin_probes(conf)
  if defined?(::Sidekiq)
    require_relative 'http_health_check/probes/sidekiq' unless defined?(Probes::Sidekiq)
    conf.probe '/readiness/sidekiq', Probes::Sidekiq.new
  end

  if defined?(::Delayed::Job)
    require_relative 'http_health_check/probes/delayed_job' unless defined?(Probes::DelayedJob)
    conf.probe '/readiness/delayed_job', Probes::DelayedJob.new
  end

  conf
end

.configure(&block) ⇒ Object



17
18
19
# File 'lib/http_health_check.rb', line 17

def self.configure(&block)
  @rack_app = RackApp.configure(&block)
end

.rack_appObject



21
22
23
# File 'lib/http_health_check.rb', line 21

def self.rack_app
  @rack_app ||= RackApp.configure { |c| add_builtin_probes(c) }
end

.run_server(port:, host: '0.0.0.0', rack_app: nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/http_health_check.rb', line 43

def self.run_server(port:, host: '0.0.0.0', rack_app: nil)
  rack_app ||= ::HttpHealthCheck.rack_app
  rack_app_with_logger = ::Rack::CommonLogger.new(rack_app, rack_app.logger)

  ::Rack::Handler::WEBrick.run(rack_app_with_logger,
                               Host: host,
                               Port: port,
                               AccessLog: [],
                               Logger: rack_app.logger)
end

.run_server_async(opts) ⇒ Object



39
40
41
# File 'lib/http_health_check.rb', line 39

def self.run_server_async(opts)
  Thread.new { run_server(**opts) }
end