Class: RailsFailover::ActiveRecord::Handler
- Inherits:
-
Object
- Object
- RailsFailover::ActiveRecord::Handler
- Includes:
- MonitorMixin, Singleton
- Defined in:
- lib/rails_failover/active_record/handler.rb
Constant Summary collapse
- VERIFY_FREQUENCY_BUFFER_PERCENT =
20
Instance Method Summary collapse
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #primaries_down_count ⇒ Object
- #primary_down?(handler_key) ⇒ Boolean
- #verify_primary(handler_key) ⇒ Object
Constructor Details
#initialize ⇒ Handler
Returns a new instance of Handler.
14 15 16 17 18 |
# File 'lib/rails_failover/active_record/handler.rb', line 14 def initialize @primaries_down = Concurrent::Map.new super() # Monitor#initialize end |
Instance Method Details
#primaries_down_count ⇒ Object
34 35 36 |
# File 'lib/rails_failover/active_record/handler.rb', line 34 def primaries_down_count primaries_down.size end |
#primary_down?(handler_key) ⇒ Boolean
30 31 32 |
# File 'lib/rails_failover/active_record/handler.rb', line 30 def primary_down?(handler_key) primaries_down[handler_key] end |
#verify_primary(handler_key) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_failover/active_record/handler.rb', line 20 def verify_primary(handler_key) primary_down(handler_key) mon_synchronize do return if @thread&.alive? logger.warn "Failover for ActiveRecord has been initiated" @thread = Thread.new { loop_until_all_up } end end |