lib/bluepill/condition_watch.rb in bluepill-0.0.5 vs lib/bluepill/condition_watch.rb in bluepill-0.0.6

- old
+ new

@@ -1,28 +1,30 @@ module Bluepill class ConditionWatch attr_accessor :logger, :name + EMPTY_ARRAY = [].freeze # no need to recreate one every tick + def initialize(name, options = {}) @name = name @logger = options.delete(:logger) - @fires = options.has_key?(:fires) ? [options.delete(:fires)].flatten : [:restart] + @fires = options.has_key?(:fires) ? Array(options.delete(:fires)) : [:restart] @every = options.delete(:every) @times = options[:times] || [1,1] @times = [@times, @times] unless @times.is_a?(Array) # handles :times => 5 self.clear_history! - @process_condition = ProcessConditions.name_to_class(@name).new(options) + @process_condition = ProcessConditions[@name].new(options) end 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 self.record_value(@process_condition.run(pid)) return @fires if self.fired? end - [] + EMPTY_ARRAY end def record_value(value) # TODO: record value in ProcessStatistics @history[@history_index] = [value, @process_condition.check(value)] \ No newline at end of file