Class: ResilientReads::HealthChecker
- Inherits:
-
Object
- Object
- ResilientReads::HealthChecker
- Defined in:
- lib/resilient_reads/health_checker.rb
Overview
Background thread that periodically verifies replica reachability. Unhealthy replicas are re-checked so they can be restored to the pool once they recover.
Instance Method Summary collapse
-
#initialize(replica_pool, interval:) ⇒ HealthChecker
constructor
A new instance of HealthChecker.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(replica_pool, interval:) ⇒ HealthChecker
Returns a new instance of HealthChecker.
6 7 8 9 10 11 |
# File 'lib/resilient_reads/health_checker.rb', line 6 def initialize(replica_pool, interval:) @replica_pool = replica_pool @interval = interval @thread = nil @running = false end |
Instance Method Details
#running? ⇒ Boolean
33 34 35 |
# File 'lib/resilient_reads/health_checker.rb', line 33 def running? @running && @thread&.alive? end |
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/resilient_reads/health_checker.rb', line 13 def start return if @replica_pool.empty? # Prevent duplicate threads — stop any existing thread first. stop if @running || @thread&.alive? @running = true @thread = Thread.new { run_loop } @thread.name = "resilient_reads_health" @thread.abort_on_exception = false @thread.report_on_exception = false end |
#stop ⇒ Object
26 27 28 29 30 31 |
# File 'lib/resilient_reads/health_checker.rb', line 26 def stop @running = false @thread&.wakeup rescue nil @thread&.join(5) rescue nil @thread = nil end |