Class: Cassanity::RetryStrategies::RetryStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/cassanity/retry_strategies/retry_strategy.rb

Direct Known Subclasses

ExponentialBackoff, RetryNTimes

Instance Method Summary collapse

Instance Method Details

#execute(payload = nil) ⇒ Object

Public: execute the given block, and handle errors raised by the Cql::Client driver. Call the retry method (overridden in your subclass) on each failed attempt with a current retry count and the error raised by the block.

payload - A Hash from an instrumenter to store a retry count in, or nil if

the number of retries shouldn't be tracked.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cassanity/retry_strategies/retry_strategy.rb', line 19

def execute(payload = nil)
  return unless block_given?

  attempt = 0

  while attempt += 1
    begin
      payload[:attempts] = attempt unless payload.nil?
      return yield
    rescue ::Cql::CqlError => e
      fail(attempt, e)
    end
  end
end

#fail(attempts, last_error) ⇒ Object

Internal: override in subclass.

attempts - how many times the unsuccessful call has been tried so far last_error - the error raised by the unsuccessful call



8
9
10
# File 'lib/cassanity/retry_strategies/retry_strategy.rb', line 8

def fail(attempts, last_error)
  raise 'not implemented'
end