helpers

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRetrierDelay = 10 * time.Second

DefaultRetrierDelay default retrier baseDelay

Variables

This section is empty.

Functions

func ImmediateTicker

func ImmediateTicker(ctx context.Context, duration time.Duration, f func() error) error

ImmediateTicker is a wrapper around time.Ticker that ticks an extra time during its creation before starting to tick on every `duration`. The reason for adding it is for multiple services that use the ticker, to be able to run their logic a single time before waiting for the `duration` to elapse. This allows for faster execution.

func ParseAddrInfos

func ParseAddrInfos(logger tmlog.Logger, addrs []string) ([]peer.AddrInfo, error)

ParseAddrInfos converts strings to AddrInfos

func TrapSignal

func TrapSignal(logger tmlog.Logger, cancel context.CancelFunc)

TrapSignal will listen for any OS signal and cancel the context to gracefully exit.

Types

type Retrier

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

Retrier handles retries of failed services.

func NewRetrier

func NewRetrier(logger tmlog.Logger, retriesNumber int, baseDelay time.Duration) *Retrier

func (Retrier) NextTick

func (r Retrier) NextTick(retryCount int) time.Duration

NextTick calculates the next exponential tick based on the provided retry count and the initialized base delay.

func (Retrier) Retry

func (r Retrier) Retry(ctx context.Context, retryMethod func() error) error

Retry retries the `retryMethod` for `r.retriesNumber` times, separated by an exponential delay calculated using the `NextTick(retryCount)` method. Returns the final execution error if all retries failed.

func (Retrier) RetryThenFail

func (r Retrier) RetryThenFail(ctx context.Context, retryMethod func() error)

RetryThenFail similar to `Retry` but panics upon failure.

Jump to

Keyboard shortcuts

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