Documentation
¶
Overview ¶
Package retry provides functionality for retrying operations with configurable backoff and jitter.
This package uses RetryError from the errors/infra package to represent errors that occur during retry operations. This is different from RetryableError in the errors/wrappers package, which is used to wrap errors that should be retried by external systems.
RetryError: Used internally by this package to indicate that all retry attempts have been exhausted. RetryableError: Used by external systems to indicate that an error should be retried.
Index ¶
- func Do(ctx context.Context, fn RetryableFunc, config Config, ...) error
- func DoWithOptions(ctx context.Context, fn RetryableFunc, config Config, ...) error
- func IsNetworkError(err error) booldeprecated
- func IsTimeoutError(err error) booldeprecated
- func IsTransientError(err error) booldeprecated
- type Config
- func (c Config) WithBackoffFactor(backoffFactor float64) Config
- func (c Config) WithInitialBackoff(initialBackoff time.Duration) Config
- func (c Config) WithJitterFactor(jitterFactor float64) Config
- func (c Config) WithMaxBackoff(maxBackoff time.Duration) Config
- func (c Config) WithMaxRetries(maxRetries int) Config
- func (c Config) WithRetryableErrors(retryableErrors []error) Config
- type IsRetryableError
- type Options
- type RetryableFunc
- type Span
- type Tracer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(ctx context.Context, fn RetryableFunc, config Config, isRetryable IsRetryableError) error
Do executes the given function with retry logic using default options
func DoWithOptions ¶
func DoWithOptions(ctx context.Context, fn RetryableFunc, config Config, isRetryable IsRetryableError, options Options) error
DoWithOptions executes the given function with retry logic and custom options
func IsNetworkError
deprecated
func IsTimeoutError
deprecated
func IsTransientError
deprecated
Types ¶
type Config ¶
type Config struct {
MaxRetries int // Maximum number of retry attempts
InitialBackoff time.Duration // Initial backoff duration
MaxBackoff time.Duration // Maximum backoff duration
BackoffFactor float64 // Factor by which the backoff increases
JitterFactor float64 // Factor for random jitter (0-1)
RetryableErrors []error // Errors that are considered retryable
}
Config contains retry configuration parameters
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default retry configuration
func (Config) WithBackoffFactor ¶
WithBackoffFactor sets the factor by which the backoff increases
func (Config) WithInitialBackoff ¶
WithInitialBackoff sets the initial backoff duration
func (Config) WithJitterFactor ¶
WithJitterFactor sets the factor for random jitter
func (Config) WithMaxBackoff ¶
WithMaxBackoff sets the maximum backoff duration
func (Config) WithMaxRetries ¶
WithMaxRetries sets the maximum number of retry attempts
func (Config) WithRetryableErrors ¶
WithRetryableErrors sets the errors that are considered retryable
type IsRetryableError ¶
IsRetryableError is a function that determines if an error is retryable
type Options ¶
type Options struct {
// Logger is used for logging retry operations
Logger *logging.ContextLogger
// Tracer is used for tracing retry operations
Tracer telemetry.Tracer
}
Options contains additional options for the retry operation
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns default options for retry operations
type RetryableFunc ¶
RetryableFunc is a function that can be retried
type Span ¶
type Span interface {
// End completes the span
End()
// SetAttributes sets attributes on the span
SetAttributes(attributes ...attribute.KeyValue)
// RecordError records an error on the span
RecordError(err error)
}
Span represents a tracing span