Class: Factorix::HTTP::RetryDecorator

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

Overview

Adds automatic retry with exponential backoff to HTTP client

Wraps any HTTP client and retries requests on network errors using the configured RetryStrategy.

Instance Method Summary collapse

Instance Method Details

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

Execute a GET request with retry

Parameters:

  • uri (URI::HTTPS)

    target URI

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

    request headers

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

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

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

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

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