Class: Philiprehberger::RetryKit::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/retry_kit/executor.rb

Constant Summary collapse

VALID_BACKOFFS =
%i[exponential linear constant].freeze
VALID_JITTERS =
%i[full equal none decorrelated].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Executor

Returns a new instance of Executor.



11
12
13
14
15
16
# File 'lib/philiprehberger/retry_kit/executor.rb', line 11

def initialize(**options)
  assign_options(options)
  validate_options!
  @last_attempts = 0
  @last_total_delay = 0.0
end

Instance Attribute Details

#last_attemptsObject (readonly)

Returns the value of attribute last_attempts.



9
10
11
# File 'lib/philiprehberger/retry_kit/executor.rb', line 9

def last_attempts
  @last_attempts
end

#last_total_delayObject (readonly)

Returns the value of attribute last_total_delay.



9
10
11
# File 'lib/philiprehberger/retry_kit/executor.rb', line 9

def last_total_delay
  @last_total_delay
end

Instance Method Details

#call(&block) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
# File 'lib/philiprehberger/retry_kit/executor.rb', line 18

def call(&block)
  raise ArgumentError, 'Block required' unless block

  @last_attempts = 0
  @last_total_delay = 0.0
  @last_decorrelated_delay = @base_delay
  @start_time = @total_timeout ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : nil

  attempt_with_retries(0, &block)
end