Documentation
¶
Index ¶
- Constants
- func Do(backoff time.Duration, action func() error)
- func Exponential(baseTime time.Duration, action func() error)
- func Fibonacci(startWaiting time.Duration, action func() error)
- func Linear(backoff, incrementStep time.Duration, action func() error)
- func NoBackoff(action func() error)
- func Polynomial(baseTime time.Duration, degree int64, action func() error)
- func Quadratic(baseTime time.Duration, action func() error)
- type Instance
- func (i *Instance) Do(backoff time.Duration, action func() error)
- func (i *Instance) Exponential(baseTime time.Duration, action func() error)
- func (i *Instance) Fibonacci(startWaiting time.Duration, action func() error)
- func (i *Instance) Linear(backoff, incrementStep time.Duration, action func() error)
- func (i *Instance) NoBackoff(action func() error)
- func (i *Instance) Polynomial(baseTime time.Duration, degree int64, action func() error)
- func (i *Instance) Quadratic(baseTime time.Duration, action func() error)
Constants ¶
const ( NoLimit = int64(0) NoDuration = time.Duration(0) )
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do is basic retry function. If action return error, it will retry after constant backoff duration. If backoff = 0, no waiting duration between action retries, same with NoBackoff().
func Exponential ¶
Exponential performs retry function with backoff time calculated by exponential function.
It will wait for baseTime to do the first retry, and then increase the waiting time by time = 2 ^ attempt * baseTime
func Fibonacci ¶
Fibonacci performs retry function with the waiting duration calculated using Fibonacci sequence.
It will wait for firstWaiting to do the first retry
func Linear ¶
Linear performs retry function with linearly incremental backoff time.
It will wait for firstWaiting to do the first retry, and then increase the waiting time by incrementStep for each next retry
func NoBackoff ¶
func NoBackoff(action func() error)
NoBackoff is a shortcut to call Do(0, action). It will retry immediately and don't wait at all.
func Polynomial ¶
Polynomial performs retry function with backoff time calculated by Polynomial function.
It will wait for baseTime to do the first retry, and then increase the waiting time by time = attempt ^ degree * baseTime
Types ¶
type Instance ¶
type Instance struct { // MaxStopRetries defines maximum number of retry times. If reach to this number, the retry will be stopped. Default: NoLimit. MaxStopRetries int64 // MaxStopDuration defines maximum total waiting duration of retry times. If total number of waiting duration is reached, the try will be stopped. Default: NoLimit. MaxStopTotalWaiting time.Duration // CeilingSleep defines max duration waiting duration during increasing. If next increasing is over this value, it keeps this value instead. Default: NoLimit. CeilingSleep time.Duration // JitterEnabled defines if Jitter is applied when calculating sleep time. Jitter adds or removes different random waiting durations to back off time. Default: false JitterEnabled bool // JitterFloorSleep is the lower bound of the random function when calculating sleep time with jitter. Default: NoLimit JitterFloorSleep time.Duration // Logger defines log output. You can use os.Stdout, file or any writer stream. Logger io.Writer }
Instance defines a goretry instance with their configs.
func (*Instance) Do ¶
Do is basic retry function. If action return error, it will retry after constant backoff duration. If backoff = 0, no waiting duration between action retries, same with NoBackoff().
func (*Instance) Exponential ¶
Exponential performs retry function with backoff time calculated by exponential function.
It will wait for baseTime to do the first retry, and then increase the waiting time by time = 2 ^ attempt * baseTime
func (*Instance) Fibonacci ¶
Fibonacci performs retry function with the waiting duration calculated using Fibonacci sequence.
It will wait for firstWaiting to do the first retry
func (*Instance) Linear ¶
Linear performs retry function with linearly incremental backoff time.
It will wait for firstWaiting to do the first retry, and then increase the waiting time by incrementStep for each next retry
func (*Instance) NoBackoff ¶
NoBackoff is a shortcut to call Do(0, action). It will retry immediately and don't wait at all.
func (*Instance) Polynomial ¶
Polynomial performs retry function with backoff time calculated by Polynomial function.
It will wait for baseTime to do the first retry, and then increase the waiting time by time = attempt ^ degree * baseTime