Class: Bluepill::ConditionWatch
- Inherits:
-
Object
- Object
- Bluepill::ConditionWatch
- Defined in:
- lib/bluepill/condition_watch.rb
Constant Summary collapse
- EMPTY_ARRAY =
no need to recreate one every tick
[].freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #clear_history! ⇒ Object
- #fired? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ ConditionWatch
constructor
A new instance of ConditionWatch.
- #run(pid, tick_number = Time.now.to_i) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ ConditionWatch
Returns a new instance of ConditionWatch.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bluepill/condition_watch.rb', line 10 def initialize(name, = {}) @name = name @logger = .delete(:logger) @fires = .has_key?(:fires) ? Array(.delete(:fires)) : [:restart] @every = .delete(:every) @times = .delete(:times) || [1,1] @times = [@times, @times] unless @times.is_a?(Array) # handles :times => 5 self.clear_history! @process_condition = ProcessConditions[@name].new() end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/bluepill/condition_watch.rb', line 7 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/bluepill/condition_watch.rb', line 7 def name @name end |
Instance Method Details
#clear_history! ⇒ Object
37 38 39 |
# File 'lib/bluepill/condition_watch.rb', line 37 def clear_history! @history = Util::RotationalArray.new(@times.last) end |
#fired? ⇒ Boolean
41 42 43 |
# File 'lib/bluepill/condition_watch.rb', line 41 def fired? @history.count {|v| not v.critical} >= @times.first end |
#run(pid, tick_number = Time.now.to_i) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bluepill/condition_watch.rb', line 24 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) @history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check(value)) self.logger.info(self.to_s) return @fires if self.fired? end EMPTY_ARRAY end |
#to_s ⇒ Object
45 46 47 48 |
# File 'lib/bluepill/condition_watch.rb', line 45 def to_s data = @history.collect {|v| "#{v.value}#{'*' unless v.critical}"}.join(", ") "#{@name}: [#{data}]\n" end |