class Wrappi::Executer::Retryer

Attributes

endpoint[R]

Public Class Methods

new(endpoint) click to toggle source
# File lib/wrappi/executer/retryer.rb, line 6
def initialize(endpoint)
  @endpoint = endpoint
end

Public Instance Methods

call() { || ... } click to toggle source
# File lib/wrappi/executer/retryer.rb, line 10
def call
  if retry?
    Retryable.retryable(retry_options) do
      res = yield
      raise RetryError if retry_if.call(res, endpoint)
      res
    end
  else
    yield
  end
end
retry?() click to toggle source
# File lib/wrappi/executer/retryer.rb, line 37
def retry?
  !!endpoint.retry_if
end
retry_if() click to toggle source
# File lib/wrappi/executer/retryer.rb, line 41
def retry_if
  endpoint.retry_if
end
retry_options() click to toggle source
# File lib/wrappi/executer/retryer.rb, line 22
def retry_options
  default = { tries: 3, on: [RetryError] }
  if endpoint.retry_options
    end_opts = endpoint.retry_options.dup
    {}.tap do |h|
      h[:tries] = end_opts[:tries] || default[:tries]
      if on = end_opts.delete(:on)
        h[:on] = default[:on] + Fusu::Array.wrap(on)
      end
    end.merge(end_opts)
  else
    default
  end
end