Class: Nerve::ServiceCheck::BaseServiceCheck
- Inherits:
-
Object
- Object
- Nerve::ServiceCheck::BaseServiceCheck
- Defined in:
- lib/nerve/service_watcher/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #catch_errors(&block) ⇒ Object
-
#initialize(opts = {}) ⇒ BaseServiceCheck
constructor
A new instance of BaseServiceCheck.
- #up? ⇒ Boolean
Methods included from Logging
configure_logger_for, #log, logger_for
Methods included from Utils
Constructor Details
#initialize(opts = {}) ⇒ BaseServiceCheck
Returns a new instance of BaseServiceCheck.
9 10 11 12 13 14 15 16 17 |
# File 'lib/nerve/service_watcher/base.rb', line 9 def initialize(opts={}) @timeout = opts['timeout'] ? opts['timeout'].to_f : 0.1 @rise = opts['rise'] ? opts['rise'].to_i : 1 @fall = opts['fall'] ? opts['fall'].to_i : 1 @name = opts['name'] ? opts['name'] : "undefined" @check_buffer = RingBuffer.new([@rise, @fall].max) @last_result = nil end |
Instance Method Details
#catch_errors(&block) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/nerve/service_watcher/base.rb', line 51 def catch_errors(&block) begin return yield rescue Object => error log.info "nerve: service check #{@name} got error #{error.inspect}" return false end end |
#up? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nerve/service_watcher/base.rb', line 19 def up? # do the check check_result = !!catch_errors do check end # this is the first check -- initialize buffer if @last_result == nil @last_result = check_result @check_buffer.size.times {@check_buffer.push check_result} log.info "nerve: service check #{@name} initial check returned #{check_result}" end log.debug "nerve: service check #{@name} returned #{check_result}" @check_buffer.push(check_result) # we've failed if the last @fall times are false unless @check_buffer.last(@fall).reduce(:|) log.info "nerve: service check #{@name} transitions to down after #{@fall} failures" if @last_result @last_result = false end # we've succeeded if the last @rise times is true if @check_buffer.last(@rise).reduce(:&) log.info "nerve: service check #{@name} transitions to up after #{@rise} successes" unless @last_result @last_result = true end # otherwise return the last result return @last_result end |