17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/glancer/utils/rate_limit_retry.rb', line 17
def self.with_retry(context:, max_retries: nil, base_delay: nil)
max_retries ||= Glancer.configuration.max_llm_retries
base_delay ||= Glancer.configuration.llm_retry_delay
attempt = 0
begin
yield
rescue StandardError => e
raise unless rate_limit_error?(e) && attempt < max_retries
attempt += 1
delay = parse_retry_after(e.message) || (base_delay * (2**(attempt - 1)))
Glancer::Utils::Logger.warn(
context,
"Rate limit hit (attempt #{attempt}/#{max_retries}). Retrying in #{delay.ceil}s..."
)
sleep(delay)
retry
end
end
|