Class: SidekiqAlive::Server::Rack

Inherits:
Object
  • Object
show all
Extended by:
Base
Defined in:
lib/sidekiq_alive/server/rack.rb

Constant Summary

Constants included from Base

Base::QUIET_SIGNAL, Base::SHUTDOWN_SIGNAL

Class Method Summary collapse

Methods included from Base

quiet!

Class Method Details

.call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sidekiq_alive/server/rack.rb', line 25

def call(env)
  req = ::Rack::Request.new(env)

  if req.path != path
    logger.warn("[SidekiqAlive] Path '#{req.path}' not found")
    return [404, {}, ["Not found"]]
  end

  if quiet?
    logger.debug("[SidekiqAlive] [SidekiqAlive] Server in quiet mode, skipping alive key lookup!")
    return [200, {}, ["Server is shutting down"]]
  end

  if SidekiqAlive.alive?
    logger.debug("[SidekiqAlive] Found alive key!")
    return [200, {}, ["Alive!"]]
  end

  response = "Can't find the alive key"
  logger.error("[SidekiqAlive] #{response}")
  [404, {}, [response]]
rescue StandardError => e
  logger.error("[SidekiqAlive] #{response} looking for alive key. Error: #{e.message}")
  [500, {}, ["Internal Server Error"]]
end

.run!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sidekiq_alive/server/rack.rb', line 11

def run!
  logger.info("[SidekiqAlive] Starting healthcheck '#{server}' server")
  @server_pid = ::Process.fork do
    @handler = handler
    configure_shutdown_signal { @handler.shutdown }
    configure_quiet_signal { @quiet = Time.now }

    @handler.run(self, Port: port, Host: host, AccessLog: [], Logger: logger)
  end
  configure_shutdown

  self
end