Class: Gracefully::RetriedCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/gracefully/retried_command.rb

Instance Method Summary collapse

Methods inherited from Command

normalize_arguments

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 = @options[: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.message, nested: e)
    end
  end
end