Sha256: 3784c097e672835cc3ade14e69864b470f92ad90d9969f8c5e394071c940bb25

Contents?: true

Size: 909 Bytes

Versions: 22

Compression:

Stored size: 909 Bytes

Contents

class LHC::Retry < LHC::Interceptor
  attr_accessor :retries, :current_retry

  class << self
    attr_accessor :max
  end

  def after_response
    response.request.options[:retries] ||= 0
    return unless retry?(response.request)
    response.request.options[:retries] += 1
    current_retry = response.request.options[:retries]
    begin
      response.request.run!
    rescue LHC::Error
      return
    end
    response.request.response if current_retry == response.request.options[:retries]
  end

  private

  def retry?(request)
    return false if request.response.success?
    return false unless request.options.dig(:retry)
    request.options[:retries] < max(request)
  end

  def max(request)
    options(request).is_a?(Hash) ? options(request).fetch(:max, LHC::Retry.max) : LHC::Retry.max
  end

  def options(request)
    @options ||= request.options.dig(:retry)
  end
end

LHC::Retry.max = 3

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
lhc-10.1.2 lib/lhc/interceptors/retry.rb
lhc-10.1.1 lib/lhc/interceptors/retry.rb
lhc-10.1.0 lib/lhc/interceptors/retry.rb
lhc-10.0.2 lib/lhc/interceptors/retry.rb
lhc-9.4.4 lib/lhc/interceptors/retry.rb
lhc-10.0.1 lib/lhc/interceptors/retry.rb
lhc-10.0.0 lib/lhc/interceptors/retry.rb
lhc-9.4.3 lib/lhc/interceptors/retry.rb
lhc-9.4.2 lib/lhc/interceptors/retry.rb
lhc-9.4.1 lib/lhc/interceptors/retry.rb
lhc-9.4.0 lib/lhc/interceptors/retry.rb
lhc-9.3.1 lib/lhc/interceptors/retry.rb
lhc-9.3.0 lib/lhc/interceptors/retry.rb
lhc-9.2.0 lib/lhc/interceptors/retry.rb
lhc-9.1.2 lib/lhc/interceptors/retry.rb
lhc-9.1.2.pre lib/lhc/interceptors/retry.rb
lhc-9.1.1 lib/lhc/interceptors/retry.rb
lhc-8.1.1 lib/lhc/interceptors/retry.rb
lhc-9.1.0 lib/lhc/interceptors/retry.rb
lhc-9.0.0 lib/lhc/interceptors/retry.rb