retry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(ctx context.Context, maxAttempts uint, backoffFunc backoff.BackoffFunc, method func(attemptTime int) error) error

Call 函数执行一个命令,并允许传递上下文、最大尝试次数和重试间隔策略函数。 Deprecated: Do not use. use MaxAttempts

Types

type Strategy

type Strategy interface {

	// Backoff 方法设置重试间隔策略函数。
	Backoff(backoffFunc backoff.BackoffFunc) Strategy

	// RetryOn 方法判断是否重试。
	RetryOn(retryOnFunc func(err error) bool) Strategy

	// Exec 方法执行一个命令,并允许传递上下文和当前尝试次数。
	Exec(ctx context.Context, cmd func(ctx context.Context, attempt uint) error) error
}

Strategy 接口定义了一个 Backoff 方法,用于设置重试间隔策略。

func MaxAttempts

func MaxAttempts(maxAttempts uint) Strategy

MaxAttempts 函数创建一个具有指定最大重试次数的 defaultStrategy 实例。

Jump to

Keyboard shortcuts

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