Module: Retry

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

Class Method Summary collapse

Class Method Details

.setup!(log: nil) ⇒ Object

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 :param log: the logger to use for retryable logging

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/issue_db/utils/retry.rb', line 10

def self.setup!(log: nil)
  raise ArgumentError, "a logger must be provided" if log.nil?

  log_method = lambda do |retries, exception|
    # :nocov:
    log.debug("[retry ##{retries}] #{exception.class}: #{exception.message} - #{exception.backtrace.join("\n")}")
    # :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("ISSUE_DB_SLEEP", 3),
      tries: ENV.fetch("ISSUE_DB_RETRIES", 10),
      log_method:
    }
  end
end