Module: Retry

Defined in:
lib/hooks/utils/retry.rb

Overview

Utility module for retry functionality

Class Method Summary collapse

Class Method Details

.setup!(log: nil, log_retries: ENV.fetch("RETRY_LOG_RETRIES", "true") == "true") ⇒ void

This method returns an undefined value.

This method should be called as early as possible in the startup of your application It sets up the Retryable gem with custom contexts and passes through a few options Should the number of retries be reached without success, the last exception will be raised

Raises:

  • (ArgumentError)

    If no logger is provided



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hooks/utils/retry.rb', line 14

def self.setup!(log: nil, log_retries: ENV.fetch("RETRY_LOG_RETRIES", "true") == "true")
  raise ArgumentError, "a logger must be provided" if log.nil?

  log_method = lambda do |retries, exception|
    # :nocov:
    if log_retries
      log.debug("[retry ##{retries}] #{exception.class}: #{exception.message} - #{exception.backtrace.join("\n")}")
    end
    # :nocov:
  end

  ######## Retryable Configuration ########
  # All defaults available here:
  # https://github.com/nfedyashev/retryable/blob/6a04027e61607de559e15e48f281f3ccaa9750e8/lib/retryable/configuration.rb#L22-L33
  Retryable.configure do |config|
    config.contexts[:default] = {
      on: [StandardError],
      sleep: ENV.fetch("DEFAULT_RETRY_SLEEP", "1").to_i,
      tries: ENV.fetch("DEFAULT_RETRY_TRIES", "10").to_i,
      log_method:
    }
  end
end