Sha256: 765a6482640ae5150c99f21e250da3190bce3c7fa1238afcb8540b9164a364d5

Contents?: true

Size: 853 Bytes

Versions: 2

Compression:

Stored size: 853 Bytes

Contents

module Rumx
  module Beans
    class TimerAndError < Timer

      bean_attr_reader     :error_count, :integer, 'Number of times the measured block has raised an exception'
      bean_attr_reader     :errors,      :list,    'List of the last occurring errors', :list_type => :bean

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

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rumx-0.1.1 lib/rumx/beans/timer_and_error.rb
rumx-0.1.0 lib/rumx/beans/timer_and_error.rb