Class: ExpRetry

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

Overview

Exponential backoff retry wrapper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ExpRetry.



12
13
14
15
16
17
18
# File 'lib/exp_retry.rb', line 12

def initialize(retries: 3, exception: StandardError, wait: 1000, verbose: false)
  @retries = retries
  @tried = 0
  @exception = exception
  @verbose = verbose
  @wait = wait
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



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

def exception
  @exception
end

#retriesObject

Returns the value of attribute retries.



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

def retries
  @retries
end

#triedObject (readonly)

Returns the value of attribute tried.



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

def tried
  @tried
end

Class Method Details

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



8
9
10
# File 'lib/exp_retry.rb', line 8

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

Instance Method Details

#callObject



20
21
22
23
24
25
# File 'lib/exp_retry.rb', line 20

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