Class: Smartsheet::API::RetryNetClientDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/smartsheet/api/retry_net_client_decorator.rb

Overview

Passes requests to the decorated client, retrying the request based on the provided RetryLogic when retry-eligible errors arise

Constant Summary collapse

SHOULD_RETRY =
->(response) { response.should_retry? }

Instance Method Summary collapse

Constructor Details

#initialize(client, retrier, logger: MuteRequestLogger.new) ⇒ RetryNetClientDecorator

Returns a new instance of RetryNetClientDecorator.



13
14
15
16
17
# File 'lib/smartsheet/api/retry_net_client_decorator.rb', line 13

def initialize(client, retrier, logger: MuteRequestLogger.new)
  @client = client
  @retrier = retrier
  @logger = logger
end

Instance Method Details

#make_request(request) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smartsheet/api/retry_net_client_decorator.rb', line 19

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