Class: Rumx::Beans::TimerAndError

Inherits:
Timer
  • Object
show all
Defined in:
lib/rumx/beans/timer_and_error.rb

Instance Method Summary collapse

Methods inherited from Timer

#avg_time, #min_time

Methods included from Rumx::Bean

add_root, #bean_add_child, #bean_children, #bean_each, #bean_each_child, #bean_each_child_recursive, #bean_each_embedded_child, #bean_each_operation, #bean_each_operation_recursive, #bean_embedded, #bean_find, #bean_get_and_set_attributes, #bean_get_attributes, #bean_has_attributes?, #bean_has_operations?, #bean_monitor, #bean_remove_child, #bean_set_and_get_attributes, #bean_set_attributes, #bean_synchronize, find, find_operation, included, remove_root, root

Constructor Details

#initialize(opts = {}) ⇒ TimerAndError

Returns a new instance of TimerAndError.



10
11
12
13
14
15
16
# File 'lib/rumx/beans/timer_and_error.rb', line 10

def initialize(opts={})
  super
  @error_count = 0
  @total_error_count = 0
  @errors = []
  @max_errors = (opts[:max_errors] || 1).to_i
end

Instance Method Details

#max_errors=(max_errors) ⇒ Object



25
26
27
28
29
30
# File 'lib/rumx/beans/timer_and_error.rb', line 25

def max_errors=(max_errors)
  bean_synchronize do
    @max_errors = max_errors
    @errors.shift while @errors.size > @max_errors
  end
end

#measureObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rumx/beans/timer_and_error.rb', line 32

def measure
  super
rescue Exception => e
  bean_synchronize do
    @error_count += 1
    @total_error_count += 1
    @errors << Message.new(e.message)
    @errors.shift while @errors.size > @max_errors
  end
  raise
end

#reset=(val) ⇒ Object



18
19
20
21
22
23
# File 'lib/rumx/beans/timer_and_error.rb', line 18

def reset=(val)
  super
  if val
    @error_count = 0
  end
end

#to_sObject



44
45
46
# File 'lib/rumx/beans/timer_and_error.rb', line 44

def to_s
  "error_count=#{@error_count}" + super
end