Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultBackOff = BackOff{ Rand: rand.New(rand.NewSource(time.Now().UnixNano())), Min: 500 * time.Millisecond, Max: 5 * time.Second, Jitter: 0.2, Factor: 2, }
View Source
var OnRetryable = Policy{ Interval: DefaultBackOff, OnCodes: RetryableCodes, Attempts: 0, }
OnRetryable is intended to be used by clients interacting with a duh rpc service. It will retry indefinitely as long as the service returns a retryable error. Users who which to cancel the indefinite retry should cancel the context.
View Source
var RetryableCodes = []int{duh.CodeRetryRequest, duh.CodeTooManyRequests, duh.CodeInternalError, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout}
RetryableCodes is a list of duh return codes which are retryable.
View Source
var Twice = Policy{ Interval: DefaultBackOff, Attempts: 2, }
Twice policy will retry 'twice' if there was an error. Uses the default back off policy
View Source
var UntilSuccess = Policy{ Interval: DefaultBackOff, Attempts: 0, }
Functions ¶
Types ¶
type BackOff ¶
type Policy ¶
type Policy struct { // Interval is an interface which dictates how long the retry should sleep between attempts. Retry comes with // two implementations called retry.BackOff which implements a backoff and retry.Sleep which is a static sleep // value with no backoff. // // backoffPolicy := retry.Policy{ // Interval: retry.BackOff{ // Min: time.Millisecond, // Max: time.Millisecond * 100, // Factor: 2, // }, // Attempts: 5, // } // // sleepPolicy := retry.Policy{ // Interval: retry.Sleep(5 * time.Seconds), // Attempts: 5, // } // Interval Interval // BackOff or Sleep // OnCodes is a list of codes which will cause a retry. If an error occurs which is not an implementation // of duh.Error and OnCodes then a retry will NOT occur. OnCodes []int // Attempts is the number of "attempts" before retry returns an error to the caller. // Attempts includes the first attempt, it is a count of the number of "total attempts" that // will be attempted. Attempts int // 0 for infinite }
Click to show internal directories.
Click to hide internal directories.