Documentation ¶
Overview ¶
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0 Package backoff provides an exponential-backoff implementation. https://github.com/jpillora/backoff inlined for customizations.
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- func GetMaxBackoffByCause(cause backendhttp.ErrorCause) time.Duration
- type Backoff
- func (b *Backoff) Attempt() float64
- func (b *Backoff) Backoff(ctx context.Context, d time.Duration)
- func (b *Backoff) Copy() *Backoff
- func (b *Backoff) Duration() time.Duration
- func (b *Backoff) DurationWithMax(max time.Duration) time.Duration
- func (b *Backoff) ForAttempt(attempt float64) time.Duration
- func (b *Backoff) ForAttemptWithMax(attempt float64, max time.Duration) time.Duration
- func (b *Backoff) IncreaseAttempt()
- func (b *Backoff) Reset()
- type RetryManager
Constants ¶
const ( DefaultFactor = 2 DefaultJitter = true DefaultMin = 1 * time.Second DefaultMax = 5 * time.Minute )
Default values
Variables ¶
This section is empty.
Functions ¶
func GetMaxBackoffByCause ¶
func GetMaxBackoffByCause(cause backendhttp.ErrorCause) time.Duration
GetMaxBackoffByCause will return the maximum backoff value based on the error cause.
Types ¶
type Backoff ¶
type Backoff struct { //Factor is the multiplying factor for each increment step Factor float64 //Jitter eases contention by randomizing backoff steps Jitter bool //Min and Max are the minimum and maximum values of the counter Min, Max time.Duration // GetBackoffTimer function to handle the backoff. GetBackoffTimer func(time.Duration) *time.Timer // contains filtered or unexported fields }
Backoff is a time.Duration counter, starting at Min. After every call to the Duration method the current timing is multiplied by Factor, but it never exceeds Max.
Backoff is not generally concurrent-safe, but the ForAttempt method can be used concurrently.
func NewDefaultBackoff ¶
func NewDefaultBackoff() *Backoff
NewDefaultBackoff default behaviour for Vortex.
func (*Backoff) Backoff ¶
Backoff waits for the specified duration or a signal from the ctx channel, whichever happens first.
func (*Backoff) DurationWithMax ¶
Duration returns the duration for the current attempt. The result will be limited to max value.
func (*Backoff) ForAttempt ¶
ForAttempt calls forAttempt with configured max/min values.
func (*Backoff) ForAttemptWithMax ¶
ForAttemptWithMax calls forAttempt with configured a max value limit.
func (*Backoff) IncreaseAttempt ¶
func (b *Backoff) IncreaseAttempt()
IncreaseAttempt increases attempt counter value.
type RetryManager ¶
type RetryManager struct {
// contains filtered or unexported fields
}
RetryManager retries using 2 different approaches: - fixed time using SetNextRetryAfter - exponential backoff using SetNextRetryWithBackoff
func NewRetrierWithBackoff ¶
func NewRetrierWithBackoff(backoff *Backoff) *RetryManager
NewRetrierWithBackoff creates a new retrier with a specific backoff
func (*RetryManager) RetryAfter ¶
func (m *RetryManager) RetryAfter() time.Duration
RetryAfter returns time to wait until next retry
func (*RetryManager) SetNextRetryAfter ¶
func (m *RetryManager) SetNextRetryAfter(duration time.Duration)
SetNextRetryAfter : sets a provided time to wait
func (*RetryManager) SetNextRetryWithBackoff ¶
func (m *RetryManager) SetNextRetryWithBackoff()
SetNextRetryWithBackoff sets a backoff for next retry that when called 2nd time it'll be increase exponentially