Class: HybiscusPdfReport::RequestRetryWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/hybiscus_pdf_report/request_retry_wrapper.rb

Overview

RequestRetryWrapper provides automatic retry logic for transient errors when communicating with the Hybiscus API (e.g., rate limits, timeouts).

Usage:

wrapper = HybiscusPdfReport::RequestRetryWrapper.new(max_attempts: 3)
wrapper.with_retries do
  api_client.perform_request
end

Retries will apply exponential backoff (1s, 2s, 4s, etc.) and will log retry attempts if a logger is provided.

Constant Summary collapse

DEFAULT_RETRY_ERRORS =
[
  RateLimitError,
  Faraday::TimeoutError,
  Faraday::ConnectionFailed
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(max_attempts: 5, base_delay: 1, logger: nil) ⇒ RequestRetryWrapper

Returns a new instance of RequestRetryWrapper.



25
26
27
28
29
# File 'lib/hybiscus_pdf_report/request_retry_wrapper.rb', line 25

def initialize(max_attempts: 5, base_delay: 1, logger: nil)
  @max_attempts = max_attempts
  @base_delay = base_delay
  @logger = logger
end

Instance Method Details

#with_retriesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hybiscus_pdf_report/request_retry_wrapper.rb', line 31

def with_retries
  attempts = 0

  begin
    yield
  rescue *DEFAULT_RETRY_ERRORS => e
    attempts += 1
    handle_retry_or_raise(e, attempts)
    retry
  end
end