pacer

package
v0.0.0-...-e7704eb Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package pacer makes pacing and retrying API calls easy

Index

Constants

View Source
const (
	// DefaultPacer is a truncated exponential attack and decay.
	//
	// On retries the sleep time is doubled, on non errors then
	// sleeptime decays according to the decay constant as set
	// with SetDecayConstant.
	//
	// The sleep never goes below that set with SetMinSleep or
	// above that set with SetMaxSleep.
	DefaultPacer = Type(iota)

	// AmazonCloudDrivePacer is a specialised pacer for Amazon Cloud Drive
	//
	// It implements a truncated exponential backoff strategy with
	// randomization.  Normally operations are paced at the
	// interval set with SetMinSleep.  On errors the sleep timer
	// is set to 0..2**retries seconds.
	//
	// See https://developer.amazon.com/public/apis/experience/cloud-drive/content/restful-api-best-practices
	AmazonCloudDrivePacer
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Paced

type Paced func() (bool, error)

Paced is a function which is called by the Call and CallNoRetry methods. It should return a boolean, true if it would like to be retried, and an error. This error may be returned or returned wrapped in a RetryError.

type Pacer

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

Pacer state

func New

func New() *Pacer

New returns a Pacer with sensible defaults

func (*Pacer) Call

func (p *Pacer) Call(fn Paced) (err error)

Call paces the remote operations to not exceed the limits and retry on rate limit exceeded

This calls fn, expecting it to return a retry flag and an error. This error may be returned wrapped in a RetryError if the number of retries is exceeded.

func (*Pacer) CallNoRetry

func (p *Pacer) CallNoRetry(fn Paced) error

CallNoRetry paces the remote operations to not exceed the limits and return a retry error on rate limit exceeded

This calls fn and wraps the output in a RetryError if it would like it to be retried

func (*Pacer) SetDecayConstant

func (p *Pacer) SetDecayConstant(decay uint) *Pacer

SetDecayConstant sets the decay constant for the pacer

This is the speed the time falls back to the minimum after errors have occurred.

bigger for slower decay, exponential

func (*Pacer) SetMaxConnections

func (p *Pacer) SetMaxConnections(n int) *Pacer

SetMaxConnections sets the maximum number of concurrent connections. Setting the value to 0 will allow unlimited number of connections. Should not be changed once you have started calling the pacer. By default this will be set to fs.Config.Checkers.

func (*Pacer) SetMaxSleep

func (p *Pacer) SetMaxSleep(t time.Duration) *Pacer

SetMaxSleep sets the maximum sleep time for the pacer

func (*Pacer) SetMinSleep

func (p *Pacer) SetMinSleep(t time.Duration) *Pacer

SetMinSleep sets the minimum sleep time for the pacer

func (*Pacer) SetPacer

func (p *Pacer) SetPacer(t Type) *Pacer

SetPacer sets the pacing algorithm

It will choose the default algorithm if an incorrect value is passed in.

func (*Pacer) SetRetries

func (p *Pacer) SetRetries(retries int) *Pacer

SetRetries sets the max number of tries for Call

type Type

type Type int

Type is for selecting different pacing algorithms

Jump to

Keyboard shortcuts

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