Class: ExpRetry

Inherits:
Object
  • Object
show all
Defined in:
lib/exp_retry.rb

Overview

Exponential backoff retry wrapper

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(retries: 3, exception: StandardError, verbose: false) ⇒ ExpRetry

Returns a new instance of ExpRetry.



9
10
11
12
13
# File 'lib/exp_retry.rb', line 9

def initialize(retries: 3, exception: StandardError, verbose: false)
  @retries = retries
  @exception = exception
  @verbose = verbose
end

Class Method Details

.for(retries: 3, exception: StandardError, verbose: false) ⇒ Object



5
6
7
# File 'lib/exp_retry.rb', line 5

def self.for(retries: 3, exception: StandardError, verbose: false)
  new(retries: retries, exception: exception, verbose: verbose).call { yield }
end

Instance Method Details

#callObject



15
16
17
18
19
20
# File 'lib/exp_retry.rb', line 15

def call
  yield if block_given?
rescue *@exception => e
  check(e)
  retry
end