addon/retry
import "github.com/gofiber/fiber/v3/addon/retry"
Variables
DefaultConfig is the default config for retry.
Source: addon/retry/config.go:38
var DefaultConfig = Config{
InitialInterval: 1 * time.Second,
MaxBackoffTime: 32 * time.Second,
Multiplier: 2.0,
MaxRetryCount: 10,
// contains filtered or unexported fields
}Functions
func NewExponentialBackoff(config ...Config) *ExponentialBackoff
Source: addon/retry/exponential_backoff.go:29
NewExponentialBackoff creates a ExponentialBackoff with default values.
Types
type Config
Source: addon/retry/config.go:8
Config defines the config for addon.
type Config struct {
// InitialInterval defines the initial time interval for backoff algorithm.
//
// Optional. Default: 1 * time.Second
InitialInterval time.Duration
// MaxBackoffTime defines maximum time duration for backoff algorithm. When
// the algorithm is reached this time, rest of the retries will be maximum
// 32 seconds.
//
// Optional. Default: 32 * time.Second
MaxBackoffTime time.Duration
// Multiplier defines multiplier number of the backoff algorithm.
//
// Optional. Default: 2.0
Multiplier float64
// MaxRetryCount defines maximum retry count for the backoff algorithm.
//
// Optional. Default: 10
MaxRetryCount int
// contains filtered or unexported fields
}Fields
InitialInterval time.DurationInitialInterval defines the initial time interval for backoff algorithm.
Optional. Default: 1 * time.Second
MaxBackoffTime time.DurationMaxBackoffTime defines maximum time duration for backoff algorithm. When the algorithm is reached this time, rest of the retries will be maximum 32 seconds.
Optional. Default: 32 * time.Second
Multiplier float64Multiplier defines multiplier number of the backoff algorithm.
Optional. Default: 2.0
MaxRetryCount intMaxRetryCount defines maximum retry count for the backoff algorithm.
Optional. Default: 10
type ExponentialBackoff
Source: addon/retry/exponential_backoff.go:10
ExponentialBackoff is a retry mechanism for retrying some calls.
type ExponentialBackoff struct {
// InitialInterval is the initial time interval for backoff algorithm.
InitialInterval time.Duration
// MaxBackoffTime is the maximum time duration for backoff algorithm. It limits
// the maximum sleep time.
MaxBackoffTime time.Duration
// Multiplier is a multiplier number of the backoff algorithm.
Multiplier float64
// MaxRetryCount is the maximum number of retry count.
MaxRetryCount int
// contains filtered or unexported fields
}Fields
InitialInterval time.DurationInitialInterval is the initial time interval for backoff algorithm.
MaxBackoffTime time.DurationMaxBackoffTime is the maximum time duration for backoff algorithm. It limits the maximum sleep time.
Multiplier float64Multiplier is a multiplier number of the backoff algorithm.
MaxRetryCount intMaxRetryCount is the maximum number of retry count.
func (e *ExponentialBackoff) Retry(f func() error) error
Source: addon/retry/exponential_backoff.go:73
Retry is the core logic of the retry mechanism. If the calling function returns nil as an error, then the Retry method is terminated with returning nil. Otherwise, if all function calls are returned error, then the method returns this error.
f is called at least once: a field left at its zero value takes its default, so even a zero ExponentialBackoff makes up to DefaultConfig.MaxRetryCount attempts.
Each call starts from InitialInterval with its own state, so one ExponentialBackoff can be shared.