class RedisHealth
Constants
- VERSION
Attributes
notifier[RW]
watchers[RW]
redis[RW]
triggered_times[RW]
Public Class Methods
configure(&blk)
click to toggle source
# File lib/redis_health.rb, line 9 def configure(&blk) instance_eval(&blk) end
new(redis)
click to toggle source
# File lib/redis_health.rb, line 27 def initialize(redis) @redis = redis @triggered_times = {} end
notify(&blk)
click to toggle source
# File lib/redis_health.rb, line 22 def notify(&blk) @notifier = blk end
watch(label, time = 60, &blk)
click to toggle source
# File lib/redis_health.rb, line 13 def watch(label, time = 60, &blk) w = { :time => time, :matcher => blk } watchers[label] = w [label, w] end
Public Instance Methods
execute_watches()
click to toggle source
# File lib/redis_health.rb, line 32 def execute_watches self.class.watchers.collect do |watcher_array| label, watcher_hash = watcher_array triggered_times[label] ||= 0 matcher_result = self.instance_eval(&watcher_hash[:matcher])#.call(@redis) triggered = matcher_result[:triggered] value = matcher_result[:value] notice = append_label_value(label, value, triggered) times_was = triggered_times[label] if triggered triggered_times[label] += 1 if times_was == watcher_hash[:time] notice end else triggered_times[label] = 0 if times_was > 0 && times_was >= watcher_hash[:time] notice else nil end end end.compact end
notify()
click to toggle source
# File lib/redis_health.rb, line 59 def notify notices = execute_watches self.class.notifier.call(notices) unless notices.empty? end
run()
click to toggle source
# File lib/redis_health.rb, line 64 def run loop do notify sleep 1 end end
Private Instance Methods
append_label_value(label, v, triggered)
click to toggle source
# File lib/redis_health.rb, line 73 def append_label_value(label, v, triggered) notice = label notice += ' is no longer in effect' unless triggered notice += ", value is now #{v}" if v notice end