Class: RetryOnError::Retrier

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*error_configs, delay:, max_wait:, &block) ⇒ Retrier

Returns a new instance of Retrier.



9
10
11
12
13
14
15
16
# File 'lib/retry_on_error/retrier.rb', line 9

def initialize(*error_configs, delay:, max_wait:, &block)
  self.error_configs = error_configs
  self.delay = delay
  self.max_wait = max_wait
  self.block = block

  validate_configs!
end

Class Method Details

.call(*error_configs, delay: 0.5, max_wait: 0, &block) ⇒ Object



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

def self.call(*error_configs, delay: 0.5, max_wait: 0, &block)
  new(*error_configs, delay: delay, max_wait: max_wait, &block).call
end

Instance Method Details

#call(start_time: Time.now) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/retry_on_error/retrier.rb', line 18

def call(start_time: Time.now)
  block.call
rescue StandardError => e
  raise unless retryable?(e, start_time: start_time)

  sleep delay

  call(start_time: start_time)
end