Class: RailsFailover::Redis::Handler
- Inherits:
-
Object
- Object
- RailsFailover::Redis::Handler
- Includes:
- MonitorMixin, Singleton
- Defined in:
- lib/rails_failover/redis/handler.rb
Constant Summary collapse
- PRIMARY_ROLE_STATUS =
"role:master"
- PRIMARY_LOADED_STATUS =
"loading:0"
- VERIFY_FREQUENCY_BUFFER_PERCENT =
20
- SOFT_DISCONNECT_TIMEOUT_SECONDS =
1
- SOFT_DISCONNECT_POLL_SECONDS =
0.05
Instance Method Summary collapse
- #deregister_client(client) ⇒ Object
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #primaries_down_count ⇒ Object
- #primary_down?(options) ⇒ Boolean
- #register_client(client) ⇒ Object
- #verify_primary(options) ⇒ Object
Constructor Details
#initialize ⇒ Handler
Returns a new instance of Handler.
19 20 21 22 23 24 |
# File 'lib/rails_failover/redis/handler.rb', line 19 def initialize @primaries_down = Concurrent::Map.new @clients = Concurrent::Map.new super() # Monitor#initialize end |
Instance Method Details
#deregister_client(client) ⇒ Object
41 42 43 44 |
# File 'lib/rails_failover/redis/handler.rb', line 41 def deregister_client(client) id = client.[:id] clients_for_id(id).delete(client) end |
#primaries_down_count ⇒ Object
50 51 52 |
# File 'lib/rails_failover/redis/handler.rb', line 50 def primaries_down_count primaries_down.size end |
#primary_down?(options) ⇒ Boolean
46 47 48 |
# File 'lib/rails_failover/redis/handler.rb', line 46 def primary_down?() primaries_down[[:id]] end |
#register_client(client) ⇒ Object
36 37 38 39 |
# File 'lib/rails_failover/redis/handler.rb', line 36 def register_client(client) id = client.[:id] clients_for_id(id).put_if_absent(client, true) end |
#verify_primary(options) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rails_failover/redis/handler.rb', line 26 def verify_primary() primary_down() mon_synchronize do return if @thread&.alive? logger&.warn "Failover for Redis has been initiated" @thread = Thread.new { loop_until_all_up } end end |