Documentation
¶
Index ¶
- Variables
- func Do(ctx context.Context, config *RetryConfig, op func() error) error
- func RetryOnError(err error) bool
- func RetryOnTemporary(err error) bool
- func RetryOnTimeout(err error) bool
- type BackoffStrategy
- type ExponentialBackoff
- type ExponentialBackoffWithJitter
- type FibonacciBackoff
- type FixedBackoff
- type LinearBackoff
- type RetryCondition
- type RetryConfig
- type RetryResult
- type Retryer
Constants ¶
This section is empty.
Variables ¶
var ExponentialBackoffDefault = ExponentialBackoffWithJitter{ Base: 100 * time.Millisecond, Max: 30 * time.Second, JitterFactor: 0.2, }
ExponentialBackoffDefault is a sensible default exponential backoff
var FixedBackoffDefault = FixedBackoff(1 * time.Second)
FixedBackoffDefault is a sensible default fixed backoff
var LinearBackoffDefault = LinearBackoff{ Base: 100 * time.Millisecond, Increment: 100 * time.Millisecond, Max: 30 * time.Second, }
LinearBackoffDefault is a sensible default linear backoff
Functions ¶
func Do ¶
func Do(ctx context.Context, config *RetryConfig, op func() error) error
Do executes the operation with retry logic
func RetryOnError ¶
RetryOnError creates a condition that retries on all errors
func RetryOnTemporary ¶
RetryOnTemporary creates a condition that retries on temporary errors
func RetryOnTimeout ¶
RetryOnTimeout creates a condition that retries only on timeout errors
Types ¶
type BackoffStrategy ¶
type BackoffStrategy interface {
// NextDelay returns the delay for the next retry attempt
// attempt starts at 1 for the first retry
NextDelay(attempt int) time.Duration
}
BackoffStrategy defines the interface for backoff strategies
type ExponentialBackoff ¶
ExponentialBackoff increases delay exponentially with each attempt
type ExponentialBackoffWithJitter ¶
type ExponentialBackoffWithJitter struct {
Base time.Duration
Max time.Duration
JitterFactor float64 // 0-1, percentage of jitter
}
ExponentialBackoffWithJitter adds jitter to exponential backoff
type FibonacciBackoff ¶
FibonacciBackoff increases delay following the Fibonacci sequence
type FixedBackoff ¶
FixedBackoff is a backoff strategy with fixed intervals
type LinearBackoff ¶
LinearBackoff increases delay linearly with each attempt
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
Backoff BackoffStrategy
RetryOn []RetryCondition
Timeout time.Duration
}
RetryConfig contains retry configuration
func DefaultRetryConfig ¶
func DefaultRetryConfig() *RetryConfig
DefaultRetryConfig returns a default retry configuration
func RetryConfigForDatabase ¶
func RetryConfigForDatabase() *RetryConfig
RetryConfigForDatabase creates a retry config optimized for database operations
func RetryConfigForIO ¶
func RetryConfigForIO() *RetryConfig
RetryConfigForIO creates a retry config optimized for I/O operations
func RetryConfigForNetwork ¶
func RetryConfigForNetwork() *RetryConfig
RetryConfigForNetwork creates a retry config optimized for network operations
type RetryResult ¶
type RetryResult struct {
Value interface{}
Error error
Attempts int
TotalTime time.Duration
LastDelay time.Duration
Success bool
}
RetryResult contains the result of a retry operation
func DoWithResult ¶
func DoWithResult(ctx context.Context, config *RetryConfig, op func() (interface{}, error)) *RetryResult
DoWithResult executes the operation with retry logic and returns a result
type Retryer ¶
type Retryer struct {
// contains filtered or unexported fields
}
Retryer is a retry helper with built-in state
func NewRetryer ¶
func NewRetryer(config *RetryConfig) *Retryer
NewRetryer creates a new Retryer with the given config