Class: Schked::LivenessProbe
- Inherits:
-
Object
- Object
- Schked::LivenessProbe
- Defined in:
- lib/schked/liveness_probe.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #healthy? ⇒ Boolean
- #heartbeat ⇒ Object
-
#initialize(config:, logger:) ⇒ LivenessProbe
constructor
A new instance of LivenessProbe.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config:, logger:) ⇒ LivenessProbe
Returns a new instance of LivenessProbe.
90 91 92 93 94 95 96 97 98 |
# File 'lib/schked/liveness_probe.rb', line 90 def initialize(config:, logger:) @config = config @logger = logger @last_heartbeat_at = nil @shutting_down = false @server = nil @thread = nil @mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
88 89 90 |
# File 'lib/schked/liveness_probe.rb', line 88 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
88 89 90 |
# File 'lib/schked/liveness_probe.rb', line 88 def logger @logger end |
Instance Method Details
#healthy? ⇒ Boolean
129 130 131 132 133 134 |
# File 'lib/schked/liveness_probe.rb', line 129 def healthy? return false if @shutting_down return false if @last_heartbeat_at.nil? Time.now - @last_heartbeat_at <= config.heartbeat_threshold end |
#heartbeat ⇒ Object
112 113 114 |
# File 'lib/schked/liveness_probe.rb', line 112 def heartbeat @last_heartbeat_at = Time.now end |
#start ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/schked/liveness_probe.rb', line 100 def start return unless config.enabled @server = create_server logger.info("Schked liveness probe listening on #{config.bind}:#{config.port}#{config.path}") @thread = Thread.new { Thread.current.name = "schked-liveness-probe" if Thread.current.respond_to?(:name=) accept_loop } end |
#stop ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/schked/liveness_probe.rb', line 116 def stop @mutex.synchronize do return if @shutting_down @shutting_down = true end sleep 0.1 @server&.close @thread&.join(5) logger.info("Schked liveness probe stopped") end |