Documentation ¶
Overview ¶
An interface for and collection of various implementations of retry behavior, designed to be easy to use and composable. See README for example uses.
Index ¶
- Variables
- func Do(ctx context.Context, strategy Strategy, action func() bool) bool
- func DoWithReset(ctx context.Context, strategy ResettableStrategy, action func() bool) bool
- type All
- type AllResettable
- type AlwaysRetryStrategy
- type Any
- type AnyResettable
- type CancelableRetryStrategy
- type CountStrategy
- type DelayStrategy
- type ExponentialBackoffStrategy
- type MaximumTimeStrategy
- type ResettableStrategy
- type Strategy
Constants ¶
This section is empty.
Variables ¶
var ( TimeFunc = time.Now SleepFunc = time.Sleep )
Set these to override how now is discovered and how sleeping is done This is mostly useful for testing, but you never know
Functions ¶
func Do ¶
Useful helper method. Calls action until it returns true or the retry strategy returns false.
func DoWithReset ¶
func DoWithReset(ctx context.Context, strategy ResettableStrategy, action func() bool) bool
Types ¶
type All ¶
type All []Strategy
A composite strategy. In order for Next or HasNext to succeed, all of the included strategies must succeed
type AllResettable ¶
type AllResettable []ResettableStrategy
func (AllResettable) HasNext ¶
func (s AllResettable) HasNext() bool
func (AllResettable) Next ¶
func (s AllResettable) Next() bool
func (AllResettable) Reset ¶
func (s AllResettable) Reset()
type AlwaysRetryStrategy ¶
type AlwaysRetryStrategy struct{}
Retry forever. No waiting.
func (*AlwaysRetryStrategy) HasNext ¶
func (s *AlwaysRetryStrategy) HasNext() bool
func (*AlwaysRetryStrategy) Next ¶
func (s *AlwaysRetryStrategy) Next() bool
type Any ¶
type Any []Strategy
A composite strategy. In order for Next or HasNext to succeed, any one of the included strategies must succeed
type AnyResettable ¶
type AnyResettable []ResettableStrategy
func (AnyResettable) HasNext ¶
func (s AnyResettable) HasNext() bool
func (AnyResettable) Next ¶
func (s AnyResettable) Next() bool
func (AnyResettable) Reset ¶
func (s AnyResettable) Reset()
type CancelableRetryStrategy ¶
type CancelableRetryStrategy struct {
// contains filtered or unexported fields
}
Always retry until canceled. Use And to combine this with other strategies to make them cancelable
func (*CancelableRetryStrategy) Cancel ¶
func (s *CancelableRetryStrategy) Cancel()
func (*CancelableRetryStrategy) HasNext ¶
func (s *CancelableRetryStrategy) HasNext() bool
func (*CancelableRetryStrategy) Next ¶
func (s *CancelableRetryStrategy) Next() bool
type CountStrategy ¶
type CountStrategy struct { Tries int // contains filtered or unexported fields }
Try up to a fixed number of times
func (*CountStrategy) HasNext ¶
func (s *CountStrategy) HasNext() bool
func (*CountStrategy) Next ¶
func (s *CountStrategy) Next() bool
func (*CountStrategy) Reset ¶
func (s *CountStrategy) Reset()
type DelayStrategy ¶
Delay strategy has no limit. It implements a fixed wait time between retries.
func (*DelayStrategy) HasNext ¶
func (s *DelayStrategy) HasNext() bool
func (*DelayStrategy) Next ¶
func (s *DelayStrategy) Next() bool
type ExponentialBackoffStrategy ¶
type ExponentialBackoffStrategy struct { InitialDelay time.Duration MaxDelay time.Duration // default: no limit // contains filtered or unexported fields }
Exponential backoff. No iteration limit, but it gets slower every time. Resettable.
func (*ExponentialBackoffStrategy) HasNext ¶
func (s *ExponentialBackoffStrategy) HasNext() bool
func (*ExponentialBackoffStrategy) Next ¶
func (s *ExponentialBackoffStrategy) Next() bool
func (*ExponentialBackoffStrategy) Reset ¶
func (s *ExponentialBackoffStrategy) Reset()
type MaximumTimeStrategy ¶
type MaximumTimeStrategy struct { Duration time.Duration // contains filtered or unexported fields }
Maximum time strategy. No iteration limit. Limit on max time. Timer starts automatically on first try. Resettable
func (*MaximumTimeStrategy) HasNext ¶
func (s *MaximumTimeStrategy) HasNext() bool
func (*MaximumTimeStrategy) Next ¶
func (s *MaximumTimeStrategy) Next() bool
func (*MaximumTimeStrategy) Reset ¶
func (s *MaximumTimeStrategy) Reset()
type ResettableStrategy ¶
type ResettableStrategy interface { Strategy Reset() }
Retry strategy expanded with reset functionality.