Documentation
¶
Overview ¶
Package retry provides retry service for gorp framework. Supports exponential backoff, jitter, customizable retry policies. Handles network errors, gRPC errors, and AppError classification.
重试包提供重试服务,用于 gorp 框架。 支持指数退避、抖动、可自定义重试策略。 处理网络错误、gRPC 错误和 AppError 分类。
Package retry provides retry service implementation. Implements retry logic with exponential backoff, jitter, and error classification.
重试包提供重试服务实现。 实现带指数退避、抖动和错误分类的重试逻辑。
Index ¶
- type Provider
- type RetryService
- func (r *RetryService) Do(ctx context.Context, fn func() error) error
- func (r *RetryService) DoForResource(ctx context.Context, resource string, fn func() error) error
- func (r *RetryService) DoWithResult(ctx context.Context, fn func() (any, error)) (any, error)
- func (r *RetryService) GetConfig() *resiliencecontract.RetryConfig
- func (r *RetryService) IsRetryable(err error) bool
- func (r *RetryService) SetPolicy(resource string, policy resiliencecontract.RetryPolicy)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct{}
Provider registers retry service. Core logic: Read retry config, create RetryService, bind to container.
Provider 注册重试服务。 核心逻辑:读取重试配置、创建 RetryService、绑定到容器。
func NewProvider ¶
func NewProvider() *Provider
NewProvider creates a new retry provider.
NewProvider 创建新的重试 provider。
func (*Provider) Boot ¶
func (p *Provider) Boot(runtimecontract.Container) error
Boot initializes the retry provider. No additional startup logic required.
Boot 初始化重试 provider。 无需额外启动逻辑。
func (*Provider) DependsOn ¶
DependsOn returns the keys this provider depends on. Retry provider depends on Config for retry configuration.
DependsOn 返回该 provider 依赖的 key。 Retry provider 依赖 Config 获取重试配置。
func (*Provider) IsDefer ¶
IsDefer indicates retry provider should defer loading. Retry is typically used by RPC client after initialization.
IsDefer 表示重试 provider 应延迟加载。 重试通常在 RPC client 初始化后使用。
type RetryService ¶
type RetryService struct {
// contains filtered or unexported fields
}
RetryService implements retry logic with configurable policy. Core logic: Execute function with retry, calculate delay with jitter, classify retryable errors.
RetryService 实现带可配置策略的重试逻辑。 核心逻辑:带重试执行函数、带抖动计算延迟、分类可重试错误。
func NewRetryService ¶
func NewRetryService(cfg *resiliencecontract.RetryConfig) *RetryService
NewRetryService creates a retry service with configuration. Core logic: Initialize random source for jitter.
NewRetryService 创建带配置的重试服务。 核心逻辑:初始化随机源用于抖动。
func (*RetryService) Do ¶
func (r *RetryService) Do(ctx context.Context, fn func() error) error
Do executes function with default retry policy. Core logic: Call doWithPolicy with default config.
Do 使用默认重试策略执行函数。 核心逻辑:调用 doWithPolicy 并使用默认配置。
func (*RetryService) DoForResource ¶
func (*RetryService) DoWithResult ¶
func (*RetryService) GetConfig ¶
func (r *RetryService) GetConfig() *resiliencecontract.RetryConfig
func (*RetryService) IsRetryable ¶
func (r *RetryService) IsRetryable(err error) bool
IsRetryable checks if error is retryable based on policy. Core logic: Check AppError reason/code, gRPC status, network error type.
IsRetryable 根据策略检查错误是否可重试。 核心逻辑:检查 AppError reason/code、gRPC status、网络错误类型。
func (*RetryService) SetPolicy ¶
func (r *RetryService) SetPolicy(resource string, policy resiliencecontract.RetryPolicy)