retry

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package retry provides a retry middleware for client.

Index

Constants

View Source
const Name = "retry"

Name is the middlewares name.

Variables

View Source
var (
	// DefaultFunc is the default retry function.
	// note that returning either false or a non-nil error will result in the call not being retried.
	DefaultFunc = OnConnectionError

	// DefaultRetries is the default number of times a request is tried.
	// Set it to 0 to disable retries.
	DefaultRetries = 5
)

Functions

func Always

func Always(_ context.Context, _ error, _ *client.CallOptions) (bool, error)

Always always retry on error. WARNING: This will retry on all errors, including business logic errors.

func OnConnectionError

func OnConnectionError(ctx context.Context, err error, options *client.CallOptions) (bool, error)

OnConnectionError retries a request on a 503/504 connection error. This is the default.

func OnTimeoutError

func OnTimeoutError(ctx context.Context, err error, options *client.CallOptions) (bool, error)

OnTimeoutError retries a request on a 408 timeout error, as well as on 503/504 connection errors.

func Provide

func Provide(configSection map[string]any, _ client.Type, logger log.Logger) (client.Middleware, error)

Provide will be registered to client.Middlewares, it's a factory for this.

Types

type Config

type Config struct {
	// RetryFunc is the retry function.
	// Default is OnConnectionError.
	RetryFunc client.RetryFunc `json:"-" yaml:"-"`

	// Retries is the number of times a request is tried.
	// Set it to 0 to disable retries.
	// Default is 5.
	Retries int `json:"retries,omitempty" yaml:"retries,omitempty"`
}

Config is the retry middleware config.

func NewConfig

func NewConfig() Config

NewConfig returns a new config object.

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware is the retry Middleware for client.

func (*Middleware) Request

Request wraps the original Request method or other middlewares.

func (*Middleware) Start

func (m *Middleware) Start(_ context.Context) error

Start the component. E.g. connect to the broker.

func (*Middleware) Stop

func (m *Middleware) Stop(_ context.Context) error

Stop the component. E.g. disconnect from the broker. The context will contain a timeout, and cancelation should be respected.

func (*Middleware) String

func (m *Middleware) String() string

String returns the name of this middleware.

func (*Middleware) Type

func (m *Middleware) Type() string

Type returns the component type, e.g. broker.

Jump to

Keyboard shortcuts

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