retry

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxDelay 默认最大等待时间
	DefaultMaxDelay = 20 * time.Second
	// DefaultBaseDelay 默认基础等待时间
	DefaultBaseDelay = 200 * time.Millisecond
	// DefaultRandomMinDelay 默认随机最小等待时间
	DefaultRandomMinDelay = 0
	// DefaultRandomMaxDelay 默认随机最大等待时间
	DefaultRandomMaxDelay = 200 * time.Millisecond
)

Variables

View Source
var DefaultFixedRetryRule = NewFixedRetryRule(DefaultBaseDelay)
View Source
var DefaultNoDelayRetryRule = NewNoDelayRetryRule()

Functions

func IsCodeExpiredCreds

func IsCodeExpiredCreds(code string) bool

func IsCodeRetryable

func IsCodeRetryable(code string) bool

func ShouldRetry

func ShouldRetry(err error) bool

ShouldRetry 判断是否需要重试 重试条件: 1.状态码为5xx 2.状态码在retryErrorCodes中 3.错误码在retryableCodes中

Types

type ExponentialRetryRule

type ExponentialRetryRule struct {
	// contains filtered or unexported fields
}

ExponentialRetryRule 指数级增长等待时间重试规则

func NewExponentialRetryRule

func NewExponentialRetryRule(baseDelay time.Duration, maxDelay time.Duration) ExponentialRetryRule

func (ExponentialRetryRule) GetDelay

func (r ExponentialRetryRule) GetDelay(attempts int) time.Duration

type FixedRetryRule

type FixedRetryRule struct {
	// contains filtered or unexported fields
}

FixedRetryRule 固定等待时间重试规则

func NewFixedRetryRule

func NewFixedRetryRule(baseDelay time.Duration) FixedRetryRule

func (FixedRetryRule) GetDelay

func (r FixedRetryRule) GetDelay(attempts int) time.Duration

type LinearRetryRule

type LinearRetryRule struct {
	// contains filtered or unexported fields
}

LinearRetryRule 线性增长等待时间重试规则

func NewLinearRetryRule

func NewLinearRetryRule(baseDelay time.Duration, maxDelay time.Duration) LinearRetryRule

func (LinearRetryRule) GetDelay

func (r LinearRetryRule) GetDelay(attempts int) time.Duration

type NoDelayRetryRule

type NoDelayRetryRule struct{}

NoDelayRetryRule 不等待重试规则(立即重试)

func NewNoDelayRetryRule

func NewNoDelayRetryRule() NoDelayRetryRule

func (NoDelayRetryRule) GetDelay

func (r NoDelayRetryRule) GetDelay(attempts int) time.Duration

type RandomRetryRule

type RandomRetryRule struct {
	// contains filtered or unexported fields
}

RandomRetryRule 随机等待时间重试规则

func NewRandomRetryRule

func NewRandomRetryRule(minDelay time.Duration, maxDelay time.Duration) RandomRetryRule

func (RandomRetryRule) GetDelay

func (r RandomRetryRule) GetDelay(attempts int) time.Duration

type RetryRule

type RetryRule interface {
	GetDelay(attempts int) time.Duration
}

RetryRule 重试等待规则

Jump to

Keyboard shortcuts

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