package retrypolicy

Import Path
	github.com/failsafe-go/failsafe-go/retrypolicy (on go.dev)

Dependency Relation
	imports 9 packages, and imported by one package

Involved Source Files Package retrypolicy provides a RetryPolicy. retry.go retryexecutor.go
Package-Level Type Names (total 3)
/* sort by: | */
ExceededError is returned when a RetryPolicy's max attempts or max duration are exceeded. This type can be used with HandleErrorTypes(retrypolicy.ExceededError{}). LastError error LastResult any ( ExceededError) Error() string ( ExceededError) Is(err error) bool ( ExceededError) Unwrap() error ExceededError : error ExceededError : golang.org/x/xerrors.Wrapper
Type Parameters: R: any RetryPolicy is a policy that defines when retries should be performed. See RetryPolicyBuilder for configuration options. This type is concurrency safe. ToExecutor returns a policy.Executor capable of handling an execution for the Policy. The typeToken parameter helps catch mismatches between R types when composing policies. github.com/failsafe-go/failsafe-go.Policy[R] (interface) RetryPolicy : github.com/failsafe-go/failsafe-go.Policy[R] func WithDefaults[R]() RetryPolicy[R] func RetryPolicyBuilder[R].Build() RetryPolicy[R]
Type Parameters: R: any RetryPolicyBuilder builds RetryPolicy instances. - By default, a RetryPolicy will retry a failed execution up to 2 times when any error is returned, with no delay between retry attempts. If retries are exceeded, ExceededError is returned by default. Alternatively, ReturnLastFailure can be used to configure the policy to return the last execution failure. - You can change the default number of retry attempts and delay between retries by using the with configuration methods. - By default, any error is considered a failure and will be handled by the policy. You can override this by specifying your own HandleErrors conditions. The default error handling condition will only be overridden by another condition that handles error such as HandleErrors or HandleIf. Specifying a condition that only handles results, such as HandleResult or HandleResultIf will not replace the default error handling condition. - If multiple HandleErrors conditions are specified, any condition that matches an execution result or error will trigger policy handling. - The AbortOn, AbortWhen and AbortIf methods describe when retries should be aborted. This class extends failsafe.FailurePolicyBuilder and failsafe.DelayablePolicyBuilder which offer additional configuration. This type is not concurrency safe. AbortIf specifies that retries should be aborted if the predicate matches the result or error. AbortOnErrorTypes specifies the errors whose types should cause retries to be aborted. Any execution errors or their Unwrapped parents whose type matches any of the errs' types will cause to be aborted. This is similar to the check that errors.As performs. AbortOnErrors specifies that retries should be aborted if the execution error matches any of the errs using errors.Is. AbortOnResult specifies that retries should be aborted if the execution result matches the result using reflect.DeepEqual. Build returns a new RetryPolicy using the builder's configuration. HandleErrorTypes specifies the errors whose types should be handled as failures. Any execution errors or their Unwrapped parents whose type matches any of the errs' types will be handled. This is similar to the check that errors.As performs. HandleErrors specifies the errors to handle as failures. Any errs that evaluate to true for errors.Is and the execution error will be handled. HandleIf specifies that a failure has occurred if the predicate matches the execution result or error. HandleResult specifies the results to handle as failures. Any result that evaluates to true for reflect.DeepEqual and the execution result will be handled. This method is only considered when a result is returned from an execution, not when an error is returned. OnAbort registers the listener to be called when an execution is aborted. OnFailure registers the listener to be called when the policy determines an execution attempt was a failure, and may be handled. OnRetriesExceeded registers the listener to be called when an execution fails and the max retry attempts or max duration are exceeded. The provided event will contain the last execution result and error. OnRetry registers the listener to be called when a retry is about to be attempted. OnRetryScheduled registers the listener to be called when a retry is about to be scheduled. This method differs from OnRetry since it is called when a retry is initially scheduled but before any configured delay, whereas OnRetry is called after a delay, just before the retry attempt takes place. OnSuccess registers the listener to be called when the policy determines an execution attempt was a success. ReturnLastFailure configures the policy to return the last failure result or error after attempts are exceeded, rather than returning ExceededError. WithBackoff wets the delay between retries, exponentially backing off to the maxDelay and multiplying consecutive delays by a factor of 2. Replaces any previously configured fixed or random delays. WithBackoffFactor sets the delay between retries, exponentially backing off to the maxDelay and multiplying consecutive delays by the delayFactor. Replaces any previously configured fixed or random delays. WithDelay configures the time to delay between execution attempts. WithDelayFunc configures a function that returns the time to delay before the next execution attempt. WithJitter sets the jitter to randomly vary retry delays by. For each retry delay, a random portion of the jitter will be added or subtracted to the delay. For example: a jitter of 100 milliseconds will randomly add between -100 and 100 milliseconds to each retry delay. Replaces any previously configured jitter factor. Jitter should be combined with fixed, random, or exponential backoff delays. If no delays are configured, this setting is ignored. WithJitterFactor sets the jitterFactor to randomly vary retry delays by. For each retry delay, a random portion of the delay multiplied by the jitterFactor will be added or subtracted to the delay. For example: a retry delay of 100 milliseconds and a jitterFactor of .25 will result in a random retry delay between 75 and 125 milliseconds. Replaces any previously configured jitter duration. Jitter should be combined with fixed, random, or exponential backoff delays. If no delays are configured, this setting is ignored. WithMaxAttempts sets the max number of execution attempts to perform. -1 indicates no limit. This method has the same effect as setting 1 more than WithMaxRetries. For example, 2 retries equal 3 attempts. WithMaxDuration sets the max duration to perform retries for, else the execution will be failed. WithMaxRetries sets the max number of retries to perform when an execution attempt fails. -1 indicates no limit. This method has the same effect as setting 1 less than WithMaxAttempts. For example, 2 retries equal 3 attempts. WithRandomDelay sets a random delay between the delayMin and delayMax (inclusive) to occur between retries. Replaces any previously configured delay or backoff delay. RetryPolicyBuilder : github.com/failsafe-go/failsafe-go.DelayablePolicyBuilder[RetryPolicyBuilder[R], R] RetryPolicyBuilder : github.com/failsafe-go/failsafe-go.FailurePolicyBuilder[RetryPolicyBuilder[R], R] func Builder[R]() RetryPolicyBuilder[R] func RetryPolicyBuilder[R].AbortIf(predicate func(R, error) bool) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].AbortOnErrors(errs ...error) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].AbortOnErrorTypes(errs ...any) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].AbortOnResult(result R) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].OnAbort(listener func(failsafe.ExecutionEvent[R])) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].OnRetriesExceeded(listener func(failsafe.ExecutionEvent[R])) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].OnRetry(listener func(failsafe.ExecutionEvent[R])) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].OnRetryScheduled(listener func(failsafe.ExecutionScheduledEvent[R])) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].ReturnLastFailure() RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithBackoff(delay time.Duration, maxDelay time.Duration) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithBackoffFactor(delay time.Duration, maxDelay time.Duration, delayFactor float32) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithJitter(jitter time.Duration) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithJitterFactor(jitterFactor float32) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithMaxAttempts(maxAttempts int) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithMaxDuration(maxDuration time.Duration) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithMaxRetries(maxRetries int) RetryPolicyBuilder[R] func RetryPolicyBuilder[R].WithRandomDelay(delayMin time.Duration, delayMax time.Duration) RetryPolicyBuilder[R]
Package-Level Functions (total 2)
Type Parameters: R: any Builder creates a RetryPolicyBuilder for execution result type R, which by default will build a RetryPolicy that allows 3 execution attempts max with no delay, unless configured otherwise.
Type Parameters: R: any WithDefaults creates a RetryPolicy for execution result type R that allows 3 execution attempts max with no delay. To configure additional options on a RetryPolicy, use Builder instead.
Package-Level Variables (only one)
ErrExceeded is a convenience error sentinel that can be used to build policies that handle ExceededError, such as via HandleErrors(retrypolicy.ErrExceeded). It can also be used with Errors.Is to determine whether an error is a retrypolicy.ExceededError.