Class: Message::Filters::RetryOnError
- Inherits:
-
Object
- Object
- Message::Filters::RetryOnError
- Defined in:
- lib/message/filters/retry_on_error.rb
Instance Attribute Summary collapse
-
#on ⇒ Object
Returns the value of attribute on.
-
#sleep ⇒ Object
Returns the value of attribute sleep.
-
#tries ⇒ Object
Returns the value of attribute tries.
Instance Method Summary collapse
- #call(filter, _, _) ⇒ Object
-
#initialize ⇒ RetryOnError
constructor
A new instance of RetryOnError.
Constructor Details
#initialize ⇒ RetryOnError
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
#on ⇒ Object
Returns the value of attribute on.
4 5 6 |
# File 'lib/message/filters/retry_on_error.rb', line 4 def on @on end |
#sleep ⇒ Object
Returns the value of attribute sleep.
4 5 6 |
# File 'lib/message/filters/retry_on_error.rb', line 4 def sleep @sleep end |
#tries ⇒ Object
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 |