backoff

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// PluginID is used to check existence of the backoff plugin
	PluginID = (*Plugin)(nil)
)

Functions

This section is empty.

Types

type Backoff

type Backoff struct {

	// MaxAttempts specifies max attempts to try before erroring
	MaxAttempts int
	// BackoffInterval is duration to increment each attempt
	BackoffInterval float64
	// Jitter specifies deviation from backoff interval
	Jitter float64

	// MinInterval specifies minimum time allowed for backoff interval
	MinInterval time.Duration
	// MaxInterval specifies maximum time allowed for backoff interval
	MaxInterval time.Duration
	// contains filtered or unexported fields
}

Backoff keeps track of connection retry attempts and calculates the delay between each one.

func DefaultBackoff

func DefaultBackoff() *Backoff

DefaultBackoff creates a default configuration for Backoff.

func (*Backoff) ForAttempt

func (b *Backoff) ForAttempt(attempt int) time.Duration

ForAttempt calculates the appropriate exponential duration given an attempt count

func (*Backoff) NextDuration

func (b *Backoff) NextDuration() time.Duration

NextDuration returns the duration and increases the number of attempts

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset resets the attempt number for Backoff.

func (*Backoff) TimeoutExceeded

func (b *Backoff) TimeoutExceeded() bool

TimeoutExceeded returns true if the backoff total duration has been exceeded

type Plugin

type Plugin struct {
	*network.Plugin
	// contains filtered or unexported fields
}

Plugin is the backoff plugin

func New added in v1.1.0

func New(opts ...PluginOption) *Plugin

New returns a new backoff plugin with specified options

func (*Plugin) PeerDisconnect

func (p *Plugin) PeerDisconnect(client *network.PeerClient)

PeerDisconnect implements the plugin callback

func (*Plugin) Startup

func (p *Plugin) Startup(net *network.Network)

Startup implements the plugin callback

type PluginOption added in v1.1.0

type PluginOption func(*Plugin)

PluginOption are configurable options for the backoff plugin

func WithInitialDelay added in v1.1.0

func WithInitialDelay(d time.Duration) PluginOption

WithInitialDelay specifies initial backoff interval

func WithMaxAttempts added in v1.1.0

func WithMaxAttempts(i int) PluginOption

WithMaxAttempts specifies max attempts to retry upon client disconnect

func WithPriority added in v1.1.0

func WithPriority(i int) PluginOption

WithPriority specifies plugin priority

Jump to

Keyboard shortcuts

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