Sha256: adfb45b958c42bc4e64e09ca274ab8c40cba36698e83880087f4d55c850c5d4f
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
module RedisFailover # Watches a specific redis node for its availability. class NodeWatcher include Util WATCHER_SLEEP_TIME = 2 def initialize(manager, node, max_failures) @manager = manager @node = node @max_failures = max_failures @monitor_thread = nil @done = false end def watch @monitor_thread = Thread.new { monitor_node } self end def shutdown @done = true @node.wakeup @monitor_thread.join if @monitor_thread rescue # best effort end private def monitor_node failures = 0 loop do begin return if @done sleep(WATCHER_SLEEP_TIME) @node.ping failures = 0 if @node.syncing_with_master? notify(:syncing) else notify(:available) @node.wait end rescue NodeUnavailableError failures += 1 if failures >= @max_failures notify(:unavailable) failures = 0 end end end end def notify(state) @manager.notify_state_change(@node, state) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
redis_failover-0.5.4 | lib/redis_failover/node_watcher.rb |
redis_failover-0.5.3 | lib/redis_failover/node_watcher.rb |