hook

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind specifies the policy type.

const (
	Static Kind = iota
	Backoff
)

type Policy

type Policy struct {
	// Type is the policy type
	Type Kind
	// Attempts to retry
	Retry int
	// Factor is the backoff rate
	Factor int
	// Sleep is the initial duration to wait before retrying
	Sleep time.Duration
}

Policy represents a retryable function policy.

func NewBackoff

func NewBackoff(retry, factor int, sleep time.Duration) *Policy

New creates a new backoff retryable policy, which increases the delay between subsequent retries by the secified factor, until the number of retries has been reached.

func NewStatic

func NewStatic(retry int, sleep time.Duration) *Policy

New creates a new static retryable policy, which retries after the duration of 'sleep', until the number of retries has been reached.

func (*Policy) Run

func (p *Policy) Run(ctx context.Context, fnc func() error) error

Run executes a function until: 1. A nil error is returned, 2. The max number of retries has been reached, 3. The specified context has been cancelled or timedout.

Jump to

Keyboard shortcuts

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