retry

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRetryPolicy = &Policy{
	MaxAttempts:       3,
	InitialBackoff:    100 * time.Millisecond,
	MaxBackoff:        1 * time.Second,
	BackoffMultiplier: 2.0,
	RetryableErrors: []codes.Code{
		codes.Unavailable,
		codes.DeadlineExceeded,
		codes.ResourceExhausted,
		codes.Internal,
	},
}

DefaultRetryPolicy 默认重试策略

Functions

func Interceptor

func Interceptor(policy *Policy) grpc.UnaryClientInterceptor

Interceptor 创建重试拦截器

Types

type Policy

type Policy struct {
	// MaxAttempts 最大重试次数(包括首次请求)
	MaxAttempts uint
	// InitialBackoff 初始重试等待时间
	InitialBackoff time.Duration
	// MaxBackoff 最大重试等待时间
	MaxBackoff time.Duration
	// BackoffMultiplier 重试等待时间的增长倍数
	BackoffMultiplier float64
	// RetryableErrors 可重试的错误码列表
	RetryableErrors []codes.Code
}

Policy 重试策略

Jump to

Keyboard shortcuts

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