Module: Teams::Common::Retry
- Defined in:
- lib/teams/common/retry.rb
Class Method Summary collapse
-
.call(max_attempts: 5, delay: 0.5, max_delay: 30.0, jitter: :full, non_retryable: [], logger: nil) ⇒ Object
Retries the block with exponential backoff, mirroring the retry helpers the TypeScript and Python SDKs use for stream sends.
Class Method Details
.call(max_attempts: 5, delay: 0.5, max_delay: 30.0, jitter: :full, non_retryable: [], logger: nil) ⇒ Object
Retries the block with exponential backoff, mirroring the retry helpers the TypeScript and Python SDKs use for stream sends. jitter :full randomizes each wait between 0 and the capped delay; :none waits the capped delay exactly.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/teams/common/retry.rb', line 12 def call(max_attempts: 5, delay: 0.5, max_delay: 30.0, jitter: :full, non_retryable: [], logger: nil) attempt = 1 begin yield rescue *non_retryable raise rescue StandardError => error raise if attempt >= max_attempts capped = [delay * (2**(attempt - 1)), max_delay].min wait = jitter == :full ? rand * capped : capped logger&.debug("retrying in #{format('%.2f', wait)}s (attempt #{attempt}/#{max_attempts}): #{error.}") sleep(wait) attempt += 1 retry end end |