Class: EventedBluepill::ProcessConditions::ProcessCondition

Inherits:
Coolio::TimerWatcher
  • Object
show all
Defined in:
lib/evented_bluepill/process_conditions/process_condition.rb

Direct Known Subclasses

AlwaysTrue, CpuUsage, Http, MemUsage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, process, options = {}) ⇒ ProcessCondition

Returns a new instance of ProcessCondition.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 16

def initialize(name, process, options = {})
  @name = name

  @logger = options.delete(:logger)
  @fires = options.delete(:fires) || :restart
  @every = options.delete(:every)
  @times = options.delete(:times) || [1,1]
  @times = [@times, @times] unless @times.is_a?(Array) # handles :times => 5
  @process = process

  self.clear_history!

  super(@every, true)
end

Instance Attribute Details

#everyObject (readonly)

Returns the value of attribute every.



14
15
16
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 14

def every
  @every
end

#firesObject (readonly)

Returns the value of attribute fires.



14
15
16
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 14

def fires
  @fires
end

#loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 13

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 14

def name
  @name
end

#processObject (readonly)

Returns the value of attribute process.



14
15
16
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 14

def process
  @process
end

#process_conditionObject (readonly)

Returns the value of attribute process_condition.



14
15
16
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 14

def process_condition
  @process_condition
end

Instance Method Details

#check(value) ⇒ Object



35
36
37
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 35

def check(value)
  raise "Implement in subclass!"
end

#clear_history!Object



43
44
45
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 43

def clear_history!
  @history = EventedBluepill::Util::RotationalArray.new(@times.last)
end

#format_value(value) ⇒ Object



39
40
41
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 39

def format_value(value)
  value
end

#runObject



31
32
33
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 31

def run
  raise "Implement in subclass!"
end

#to_sObject



47
48
49
50
# File 'lib/evented_bluepill/process_conditions/process_condition.rb', line 47

def to_s
  data = @history.collect {|v| "#{v.value}#{'*' unless v.critical}"}.join(", ")
  "#{@name}: [#{data}]"
end