Class: Message::Filters::RetryOnError

Inherits:
Object
  • Object
show all
Defined in:
lib/message/filters/retry_on_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRetryOnError

Returns a new instance of RetryOnError.



5
6
7
8
9
# File 'lib/message/filters/retry_on_error.rb', line 5

def initialize
  @tries = 3
  @on = StandardError
  @sleep = 0.001
end

Instance Attribute Details

#onObject

Returns the value of attribute on.



4
5
6
# File 'lib/message/filters/retry_on_error.rb', line 4

def on
  @on
end

#sleepObject

Returns the value of attribute sleep.



4
5
6
# File 'lib/message/filters/retry_on_error.rb', line 4

def sleep
  @sleep
end

#triesObject

Returns the value of attribute tries.



4
5
6
# File 'lib/message/filters/retry_on_error.rb', line 4

def tries
  @tries
end

Instance Method Details

#call(filter, _, _) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/message/filters/retry_on_error.rb', line 11

def call(filter, _, _)
  lambda do |arg|
    @try = 0
    begin
      filter.call(arg)
    rescue self.on => e
      @try += 1
      if @try < self.tries
        Kernel.sleep self.sleep.to_f
        retry
      end
      raise
    end
  end
end