retry

package
v0.0.0-...-e51fe83 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackOffDelayPolicy

func BackOffDelayPolicy(attempts uint, _ error, retryConfig *Config) time.Duration

BackOffDelayPolicy is a DelayPolicyFunc which exponentially increases delay between consecutive retries, if the retryConfig.Delay less than or equal to 0, the final delay is 0

func DefaultDelayPolicy

func DefaultDelayPolicy(_ uint, _ error, _ *Config) time.Duration

DefaultDelayPolicy is a DelayPolicyFunc which keep 0 delay in all iterations

func Delay

func Delay(attempts uint, err error, retryConfig *Config) time.Duration

Delay generate the delay time required for the current retry config, if the retryConfig.DelayPolicy == nil, the final delay is 0

func FixedDelayPolicy

func FixedDelayPolicy(_ uint, _ error, retryConfig *Config) time.Duration

FixedDelayPolicy is a DelayPolicyFunc which keeps delay the same through all iterations

func RandomDelayPolicy

func RandomDelayPolicy(_ uint, _ error, retryConfig *Config) time.Duration

RandomDelayPolicy is a DelayPolicyFunc which picks a random delay up to RetryConfig.MaxJitter, if the retryConfig.MaxJitter less than or equal to 0, the final delay is 0

Types

type Config

type Config struct {
	// The maximum number of call attempt times, including the initial call
	MaxAttemptTimes uint

	// Initial retry delay time
	Delay time.Duration

	// Maximum retry delay time. When the retry time increases beyond this time,
	// this configuration will limit the upper limit of waiting time
	MaxDelay time.Duration

	// The maximum jitter time, which takes effect when the delay policy is configured as RandomDelay
	MaxJitter time.Duration

	// Delay strategy, which can combine multiple delay strategies. such as CombineDelay(BackOffDelayPolicy, RandomDelayPolicy) or BackOffDelayPolicy,etc
	DelayPolicy DelayPolicyFunc
}

Config All configurations related to retry

func (*Config) Apply

func (o *Config) Apply(opts []Option)

type DelayPolicyFunc

type DelayPolicyFunc func(attempts uint, err error, retryConfig *Config) time.Duration

DelayPolicyFunc signature of delay policy function is called to return the delay of retry

func CombineDelay

func CombineDelay(delays ...DelayPolicyFunc) DelayPolicyFunc

CombineDelay return DelayPolicyFunc, which combines the optional DelayPolicyFunc into a new DelayPolicyFunc

type Option

type Option struct {
	F func(o *Config)
}

Option is the only struct that can be used to set Retry Config.

func WithDelayPolicy

func WithDelayPolicy(delayPolicy DelayPolicyFunc) Option

WithDelayPolicy set DelayPolicy.

func WithInitDelay

func WithInitDelay(delay time.Duration) Option

WithInitDelay set init Delay.

func WithMaxAttemptTimes

func WithMaxAttemptTimes(maxAttemptTimes uint) Option

WithMaxAttemptTimes set WithMaxAttemptTimes , including the first call.

func WithMaxDelay

func WithMaxDelay(maxDelay time.Duration) Option

WithMaxDelay set MaxDelay.

func WithMaxJitter

func WithMaxJitter(maxJitter time.Duration) Option

WithMaxJitter set MaxJitter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL