Documentation ¶
Overview ¶
Package pacer makes pacing and retrying API calls easy
Index ¶
- Constants
- type Paced
- type Pacer
- func (p *Pacer) Call(fn Paced) (err error)
- func (p *Pacer) CallNoRetry(fn Paced) error
- func (p *Pacer) SetDecayConstant(decay uint) *Pacer
- func (p *Pacer) SetMaxConnections(n int) *Pacer
- func (p *Pacer) SetMaxSleep(t time.Duration) *Pacer
- func (p *Pacer) SetMinSleep(t time.Duration) *Pacer
- func (p *Pacer) SetPacer(t Type) *Pacer
- func (p *Pacer) SetRetries(retries int) *Pacer
- type Type
Constants ¶
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 ¶
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 (*Pacer) Call ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetMaxSleep sets the maximum sleep time for the pacer
func (*Pacer) SetMinSleep ¶
SetMinSleep sets the minimum sleep time for the pacer
func (*Pacer) SetPacer ¶
SetPacer sets the pacing algorithm
It will choose the default algorithm if an incorrect value is passed in.
func (*Pacer) SetRetries ¶
SetRetries sets the max number of tries for Call