Class: Cassanity::RetryStrategies::RetryNTimes

Inherits:
RetryStrategy show all
Defined in:
lib/cassanity/retry_strategies/retry_n_times.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RetryStrategy

#execute

Constructor Details

#initialize(args = {}) ⇒ RetryNTimes

Public: initialize the retry strategy.

args - The Hash of arguments.

:retries - the number of times to retry an unsuccessful call
           before failing.


14
15
16
17
18
# File 'lib/cassanity/retry_strategies/retry_n_times.rb', line 14

def initialize(args = {})
  # By default, there's no retries - if the call fails, you
  # get the error propagated to you.
  @retries = args[:retries] || 0
end

Instance Attribute Details

#retriesObject (readonly)

Private



7
8
9
# File 'lib/cassanity/retry_strategies/retry_n_times.rb', line 7

def retries
  @retries
end

Instance Method Details

#fail(attempts, error) ⇒ Object

Private: re-raise the exception from the last call if it’s been retried more than the maximum allowed amount.



22
23
24
25
26
# File 'lib/cassanity/retry_strategies/retry_n_times.rb', line 22

def fail(attempts, error)
  if attempts > @retries
    raise error
  end
end