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.
Constant Summary collapse
- RETRYABLE_STATUSES =
[429, 503].freeze
- MAX_DELAY =
Maximum delay cap in seconds
30
Class Method Summary collapse
-
.call(max_attempts: 3, base_delay: 1) { ... } ⇒ 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.
34 35 36 37 38 |
# File 'lib/skill_bench/clients/retry_handler.rb', line 34 def initialize(max_attempts:, base_delay:, block:) @max_attempts = max_attempts @base_delay = base_delay @block = block end |
Class Method Details
.call(max_attempts: 3, base_delay: 1) { ... } ⇒ Object
Executes the given block with retry logic.
24 25 26 27 28 29 |
# File 'lib/skill_bench/clients/retry_handler.rb', line 24 def self.call(max_attempts: 3, base_delay: 1, &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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/skill_bench/clients/retry_handler.rb', line 44 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 |