lib/bluepill/condition_watch.rb in bluepill-0.0.68 vs lib/bluepill/condition_watch.rb in bluepill-0.0.69

- old
+ new

@@ -1,6 +1,5 @@ -# -*- encoding: utf-8 -*- module Bluepill class HistoryValue < Struct.new(:value, :critical) end class ConditionWatch @@ -9,13 +8,13 @@ def initialize(name, options = {}) @name = name @logger = options.delete(:logger) - @fires = options.has_key?(:fires) ? Array(options.delete(:fires)) : [:restart] + @fires = options.key?(:fires) ? Array(options.delete(:fires)) : [:restart] @every = options.delete(:every) - @times = options.delete(:times) || [1,1] + @times = options.delete(:times) || [1, 1] @times = [@times, @times] unless @times.is_a?(Array) # handles :times => 5 @include_children = options.delete(:include_children) || false self.clear_history! @@ -24,13 +23,19 @@ def run(pid, tick_number = Time.now.to_i) if @last_ran_at.nil? || (@last_ran_at + @every) <= tick_number @last_ran_at = tick_number - value = @process_condition.run(pid, @include_children) + begin + value = @process_condition.run(pid, @include_children) + rescue => e + logger.err(e.backtrace) + raise e + end + @history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check(value)) - self.logger.info(self.to_s) + logger.info(to_s) return @fires if self.fired? end EMPTY_ARRAY end @@ -38,14 +43,14 @@ def clear_history! @history = Util::RotationalArray.new(@times.last) end def fired? - @history.count {|v| not v.critical} >= @times.first + @history.count { |v| !v.critical } >= @times.first end def to_s - data = @history.collect {|v| "#{v.value}#{'*' unless v.critical}"}.join(", ") + data = @history.collect { |v| "#{v.value}#{'*' unless v.critical}" }.join(', ') "#{@name}: [#{data}]\n" end end end