Sha256: 2c7fc03e265d009bf84755d4ccb75602fddf4f4bcf377bd807141dad460d2745
Contents?: true
Size: 1.06 KB
Versions: 6
Compression:
Stored size: 1.06 KB
Contents
require 'smartsheet/api/request_logger' module Smartsheet module API # Passes requests to the decorated client, retrying the request based on the provided # {RetryLogic} when retry-eligible errors arise class RetryNetClientDecorator SHOULD_RETRY = ->(response) { response.should_retry? } attr_reader :client, :retrier, :logger private :client, :retrier, :logger def initialize(client, retrier, logger: MuteRequestLogger.new) @client = client @retrier = retrier @logger = logger end def make_request(request) total_attempts = 0 retried_response = retrier.run(SHOULD_RETRY) do |iteration| response = client.make_request(request) total_attempts = iteration + 1 logger.log_retry_attempt(request, response, total_attempts) if SHOULD_RETRY.call(response) response end unless retried_response.success? || total_attempts < 2 logger.log_retry_failure(total_attempts) end retried_response end end end end
Version data entries
6 entries across 6 versions & 1 rubygems