// WithExponentialBackoff will retry webhookFn() up to 5 times with exponentially increasing backoff when // it returns an error for which apierrors.SuggestsClientDelay() or apierrors.IsInternalError() returns true. func (g *GenericWebhook) WithExponentialBackoff(webhookFn func() restclient.Result) restclient.Result { var result restclient.Result WithExponentialBackoff(g.initialBackoff, func() error { result = webhookFn() return result.Error() }) return result }
// WithExponentialBackoff will retry webhookFn 5 times w/ exponentially // increasing backoff when a 429 or a 5xx response code is returned. func (g *GenericWebhook) WithExponentialBackoff(webhookFn func() restclient.Result) restclient.Result { backoff := wait.Backoff{ Duration: g.initialBackoff, Factor: 1.5, Jitter: 0.2, Steps: 5, } var result restclient.Result wait.ExponentialBackoff(backoff, func() (bool, error) { result = webhookFn() // Return from Request.Do() errors immediately. if err := result.Error(); err != nil { return false, err } // Retry 429s, and 5xxs. var statusCode int if result.StatusCode(&statusCode); statusCode == 429 || statusCode >= 500 { return false, nil } return true, nil }) return result }