Sha256: 7b2433ee505f91cdca9108888ff44e460aee1d428367de46d79e196fe5ce1326
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
module RedisFailover # NodeWatcher periodically monitors a specific redis node for its availability. # NodeWatcher instances periodically report a redis node's current state # to the NodeManager for proper handling. class NodeWatcher include Util # Time to sleep before checking on the monitored node's status. 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(@node, state) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redis_failover-0.8.0 | lib/redis_failover/node_watcher.rb |