Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RetryWithBackoff ¶
func RetryWithBackoff[T any](ctx context.Context, cfg RetryConfig, operation string, isRetryable func(error) bool, fn func() (T, error)) (T, error)
RetryWithBackoff executes the given function with exponential backoff retry. It only retries on errors that are classified as retryable by the provided isRetryable function.
Types ¶
type RetryConfig ¶
type RetryConfig struct {
// MaxRetries is the maximum number of retry attempts (default: 5)
// 0 means do not retry at all.
MaxRetries int
// BaseBackoff is the initial backoff duration (default: 1s, higher than typical due to quota nature)
BaseBackoff time.Duration
// MaxBackoff is the maximum backoff duration (default: 60s)
MaxBackoff time.Duration
// MaxJitter is the maximum random jitter added to backoff (default: 500ms)
MaxJitter time.Duration
}
RetryConfig configures retry behavior for API calls. This is particularly useful for handling rate limit and transient server errors.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns a retry configuration suitable for quota and rate limit errors. Uses longer backoffs than typical retry configs because quota-based rate limits often require more time to recover.
func (RetryConfig) Validate ¶
func (c RetryConfig) Validate() error
Validate checks that the retry configuration has valid values.
Click to show internal directories.
Click to hide internal directories.