Class: Factorix::HTTP::RetryDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/http/retry_decorator.rb,
sig/factorix/http/retry_decorator.rbs

Overview

Decorator that adds retry functionality to an HTTP client

Automatically retries transient errors (timeouts, connection issues) using an exponential backoff strategy with randomization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client ⇒ Client (readonly)

Returns the value of attribute client.

Returns:



12
13
14
# File 'sig/factorix/http/retry_decorator.rbs', line 12

def client
  @client
end

#logger ⇒ Dry::Logger::Dispatcher (readonly)

Returns the value of attribute logger.



14
15
16
# File 'sig/factorix/http/retry_decorator.rbs', line 14

def logger
  @logger
end

#retry_strategy ⇒ RetryStrategy (readonly)

Returns the value of attribute retry_strategy.

Returns:



13
14
15
# File 'sig/factorix/http/retry_decorator.rbs', line 13

def retry_strategy
  @retry_strategy
end

Instance Method Details

#get(uri, headers: {}) {|Net::HTTPResponse| ... } ⇒ Response

Execute a GET request with retry logic

Parameters:

  • uri (URI::HTTPS) —

    target URI

  • headers (Hash<String, String>) (defaults to: {}) —

    request headers

  • headers: (Hash[String, String]) (defaults to: {})

Yields:

  • (Net::HTTPResponse) —

    for streaming responses

Returns:



39
40
41
42
43
# File 'lib/factorix/http/retry_decorator.rb', line 39

def get(uri, headers: {}, &block)
  retry_strategy.with_retry do
    client.get(uri, headers:, &block)
  end
end

#head(uri, headers: {}) ⇒ Response

Execute a HEAD request with retry

Parameters:

  • uri (URI::HTTPS) —

    target URI

  • headers (Hash<String, String>) (defaults to: {}) —

    request headers

Returns:



63
64
65
66
67
# File 'lib/factorix/http/retry_decorator.rb', line 63

def head(uri, headers: {})
  retry_strategy.with_retry do
    client.head(uri, headers:)
  end
end

#post(uri, body:, headers: {}, content_type: nil) ⇒ Response

Execute a POST request with retry logic

Parameters:

  • uri (URI::HTTPS) —

    target URI

  • body (String, IO) —

    request body

  • headers (Hash<String, String>) (defaults to: {}) —

    request headers

  • content_type (String, nil) (defaults to: nil) —

    Content-Type header

  • body: (String, IO)
  • headers: (Hash[String, String]) (defaults to: {})
  • content_type: (String, nil) (defaults to: nil)

Returns:



52
53
54
55
56
# File 'lib/factorix/http/retry_decorator.rb', line 52

def post(uri, body:, headers: {}, content_type: nil)
  retry_strategy.with_retry do
    client.post(uri, body:, headers:, content_type:)
  end
end

#request(method, uri, headers: {}, body: nil) {|Net::HTTPResponse| ... } ⇒ Response

Execute an HTTP request with retry logic

Parameters:

  • method (Symbol) —

    HTTP method

  • uri (URI::HTTPS) —

    target URI

  • headers (Hash<String, String>) (defaults to: {}) —

    request headers

  • body (String, IO, nil) (defaults to: nil) —

    request body

  • headers: (Hash[String, String]) (defaults to: {})
  • body: (String, IO, nil) (defaults to: nil)

Yields:

  • (Net::HTTPResponse) —

    for streaming responses

Returns:



27
28
29
30
31
# File 'lib/factorix/http/retry_decorator.rb', line 27

def request(method, uri, headers: {}, body: nil, &block)
  retry_strategy.with_retry do
    client.request(method, uri, headers:, body:, &block)
  end
end