Class: SkillBench::Clients::RetryHandler
- Inherits:
-
Object
- Object
- SkillBench::Clients::RetryHandler
- Defined in:
- lib/skill_bench/clients/retry_handler.rb
Overview
Service object for retrying HTTP requests with exponential backoff. Retries on transient errors (429, 503). Raises permanent errors immediately. Returns the block result on success.
Class Method Summary collapse
-
.call(max_attempts: Constants::HttpClient::DEFAULT_MAX_RETRIES, base_delay: Constants::HttpClient::DEFAULT_RETRY_DELAY) { ... } ⇒ Object
Executes the given block with retry logic.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the block with retry logic.
-
#initialize(max_attempts:, base_delay:, block:) ⇒ RetryHandler
constructor
A new instance of RetryHandler.
Constructor Details
#initialize(max_attempts:, base_delay:, block:) ⇒ RetryHandler
Returns a new instance of RetryHandler.
31 32 33 34 35 |
# File 'lib/skill_bench/clients/retry_handler.rb', line 31 def initialize(max_attempts:, base_delay:, block:) @max_attempts = max_attempts @base_delay = base_delay @block = block end |
Class Method Details
.call(max_attempts: Constants::HttpClient::DEFAULT_MAX_RETRIES, base_delay: Constants::HttpClient::DEFAULT_RETRY_DELAY) { ... } ⇒ Object
Executes the given block with retry logic.
21 22 23 24 25 26 |
# File 'lib/skill_bench/clients/retry_handler.rb', line 21 def self.call(max_attempts: Constants::HttpClient::DEFAULT_MAX_RETRIES, base_delay: Constants::HttpClient::DEFAULT_RETRY_DELAY, &block) raise ArgumentError, 'RetryHandler requires a block' unless block raise ArgumentError, 'max_attempts must be >= 1' if max_attempts < 1 new(max_attempts:, base_delay:, block:).call end |
Instance Method Details
#call ⇒ Object
Executes the block with retry logic.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/skill_bench/clients/retry_handler.rb', line 41 def call attempt = 0 loop do attempt += 1 return @block.call rescue Faraday::Error => e status = extract_status(e) raise e unless retryable?(status, attempt) delay = compute_delay(attempt) wait(delay) end end |