Class: Gracefully::RetriedCommand
- Defined in:
- lib/gracefully/retried_command.rb
Instance Method Summary collapse
- #call(*args, &block) ⇒ Object
-
#initialize(*args, &block) ⇒ RetriedCommand
constructor
A new instance of RetriedCommand.
Methods inherited from Command
Constructor Details
#initialize(*args, &block) ⇒ RetriedCommand
Returns a new instance of RetriedCommand.
5 6 7 8 9 |
# File 'lib/gracefully/retried_command.rb', line 5 def initialize(*args, &block) super @retries = [:retries] end |
Instance Method Details
#call(*args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gracefully/retried_command.rb', line 11 def call(*args, &block) num_tried = 0 begin @callable.call *args, &block rescue => e num_tried += 1 if num_tried <= @retries retry else raise Gracefully::Error.new(e., nested: e) end end end |