retry

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 11 Imported by: 0

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

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

Boot initializes the retry provider. No additional startup logic required.

Boot 初始化重试 provider。 无需额外启动逻辑。

func (*Provider) DependsOn

func (p *Provider) DependsOn() []string

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

func (p *Provider) IsDefer() bool

IsDefer indicates retry provider should defer loading. Retry is typically used by RPC client after initialization.

IsDefer 表示重试 provider 应延迟加载。 重试通常在 RPC client 初始化后使用。

func (*Provider) Name

func (p *Provider) Name() string

Name returns provider name for identification.

Name 返回 provider 名称,用于标识。

func (*Provider) Provides

func (p *Provider) Provides() []string

Provides returns the capability keys this provider exposes. Exposes RetryKey for retry service.

Provides 返回 provider 暴露的能力键。 暴露 RetryKey 用于重试服务。

func (*Provider) Register

func (p *Provider) Register(c runtimecontract.Container) error

Register binds the retry factory to the container. Core logic: Read config, create RetryService with policy, bind to container.

Register 将重试工厂绑定到容器。 核心逻辑:读取配置、创建带策略的 RetryService、绑定到容器。

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 (r *RetryService) DoForResource(ctx context.Context, resource string, fn func() error) error

func (*RetryService) DoWithResult

func (r *RetryService) DoWithResult(ctx context.Context, fn func() (any, error)) (any, error)

func (*RetryService) GetConfig

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)

Directories

Path Synopsis
Application scenarios: - Provide the monolith-friendly no-op retry capability.
Application scenarios: - Provide the monolith-friendly no-op retry capability.

Jump to

Keyboard shortcuts

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