Documentation
¶
Index ¶
- Variables
- func CompileConditions(patterns []string) ([]*regexp.Regexp, error)
- func DefaultConfig() schema.RetryConfig
- func Do(ctx context.Context, config *schema.RetryConfig, fn Func) error
- func MatchesAny(patterns []*regexp.Regexp, output string) bool
- func Validate(config *schema.RetryConfig) error
- func With7Params[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](ctx context.Context, config *schema.RetryConfig, ...) error
- func WithPredicate(ctx context.Context, config *schema.RetryConfig, fn Func, ...) error
- type Executor
- type Func
- type MaxElapsedTimeError
Constants ¶
This section is empty.
Variables ¶
var ( ErrMaxAttemptsMustBePositive = errors.New("max_attempts must be greater than zero") ErrMaxElapsedTimeMustBePositive = errors.New("max_elapsed_time must be greater than zero") ErrMultiplierMustBePositive = errors.New("multiplier must be greater than zero") ErrMaxDelayMustBePositive = errors.New("max_delay must be greater than zero") ErrInitialDelayCannotBeNegative = errors.New("initial_delay cannot be negative") ErrRandomJitterOutOfRange = errors.New("random_jitter must be between 0.0 and 1.0") )
Validation errors.
var ErrInvalidCondition = errors.New("invalid retry condition pattern")
ErrInvalidCondition is returned when a retry condition pattern fails to compile.
var UnexpectedError = errors.New("unexpected end of retry loop")
UnexpectedError is returned when the retry loop ends unexpectedly.
Functions ¶
func CompileConditions ¶
CompileConditions compiles a slice of regex pattern strings into a slice of *regexp.Regexp. Patterns may be wrapped in optional /.../ delimiters for readability — surrounding slashes are stripped before compilation. An empty or nil input returns (nil, nil). A pattern that fails to compile produces an error joined with ErrInvalidCondition.
func DefaultConfig ¶
func DefaultConfig() schema.RetryConfig
DefaultConfig returns a sensible default configuration for a single attempt. Most fields are nil (disabled/unlimited).
func Do ¶
Do is a convenience function that creates an executor and runs the function. If config is nil, a default single-attempt config is used to ensure consistent error messages (e.g., "max attempts (1) exceeded, last error: ...").
func MatchesAny ¶
MatchesAny reports whether any of the compiled patterns matches the given output. Returns false when patterns is empty or output is empty.
func Validate ¶ added in v1.207.0
func Validate(config *schema.RetryConfig) error
Validate checks that explicitly set values are valid. Returns an error if any field is explicitly set to an invalid value (e.g., zero or negative). Nil values are valid and mean "disabled" or "unlimited".
func With7Params ¶
func With7Params[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](ctx context.Context, config *schema.RetryConfig, fn func(T1, T2, T3, T4, T5, T6, T7) error, a T1, b T2, c T3, d T4, e T5, f T6, g T7, ) error
With7Params is a convenience function for retrying functions with 7 parameters.
func WithPredicate ¶
func WithPredicate(ctx context.Context, config *schema.RetryConfig, fn Func, shouldRetry func(error) bool) error
WithPredicate allows you to specify which errors should trigger a retry. If config is nil, the function is executed once without retry.
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles the retry logic.
func New ¶
func New(config schema.RetryConfig) *Executor
New creates a new retry executor with the given config.
type MaxElapsedTimeError ¶
MaxElapsedTimeError is returned when the retry timeout is exceeded.
func (MaxElapsedTimeError) Error ¶
func (e MaxElapsedTimeError) Error() string