Documentation
¶
Overview ¶
Package policy provides types that are used for implementing a failsafe.Policy.
Index ¶
- type BaseAbortablePolicy
- func (c *BaseAbortablePolicy[R]) AbortIf(predicate func(R, error) bool)
- func (c *BaseAbortablePolicy[R]) AbortOnErrorTypes(errs ...any)
- func (c *BaseAbortablePolicy[R]) AbortOnErrors(errs ...error)
- func (c *BaseAbortablePolicy[R]) AbortOnResult(result R)
- func (c *BaseAbortablePolicy[R]) IsAbortable(result R, err error) bool
- func (c *BaseAbortablePolicy[R]) IsConfigured() bool
- type BaseDelayablePolicy
- type BaseExecutor
- func (e *BaseExecutor[R]) Apply(innerFn func(failsafe.Execution[R]) *common.PolicyResult[R]) func(failsafe.Execution[R]) *common.PolicyResult[R]
- func (e *BaseExecutor[R]) IsFailure(result R, err error) bool
- func (e *BaseExecutor[R]) OnFailure(exec ExecutionInternal[R], result *common.PolicyResult[R]) *common.PolicyResult[R]
- func (e *BaseExecutor[R]) OnSuccess(exec ExecutionInternal[R], result *common.PolicyResult[R])
- func (e *BaseExecutor[R]) PostExecute(exec ExecutionInternal[R], er *common.PolicyResult[R]) *common.PolicyResult[R]
- func (e *BaseExecutor[R]) PreExecute(_ ExecutionInternal[R]) *common.PolicyResult[R]
- type BaseFailurePolicy
- func (p *BaseFailurePolicy[R]) HandleErrorTypes(errs ...any)
- func (p *BaseFailurePolicy[R]) HandleErrors(errs ...error)
- func (p *BaseFailurePolicy[R]) HandleIf(predicate func(R, error) bool)
- func (p *BaseFailurePolicy[R]) HandleResult(result R)
- func (p *BaseFailurePolicy[R]) IsFailure(result R, err error) bool
- func (p *BaseFailurePolicy[R]) OnFailure(listener func(event failsafe.ExecutionEvent[R]))
- func (p *BaseFailurePolicy[R]) OnSuccess(listener func(event failsafe.ExecutionEvent[R]))
- type ExecutionInternal
- type Executor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseAbortablePolicy ¶ added in v0.5.0
type BaseAbortablePolicy[R any] struct { // contains filtered or unexported fields }
BaseAbortablePolicy provides a base for implementing policies that can be aborted or canceled.
func (*BaseAbortablePolicy[R]) AbortIf ¶ added in v0.5.0
func (c *BaseAbortablePolicy[R]) AbortIf(predicate func(R, error) bool)
func (*BaseAbortablePolicy[R]) AbortOnErrorTypes ¶ added in v0.6.7
func (c *BaseAbortablePolicy[R]) AbortOnErrorTypes(errs ...any)
func (*BaseAbortablePolicy[R]) AbortOnErrors ¶ added in v0.5.0
func (c *BaseAbortablePolicy[R]) AbortOnErrors(errs ...error)
func (*BaseAbortablePolicy[R]) AbortOnResult ¶ added in v0.5.0
func (c *BaseAbortablePolicy[R]) AbortOnResult(result R)
func (*BaseAbortablePolicy[R]) IsAbortable ¶ added in v0.5.0
func (c *BaseAbortablePolicy[R]) IsAbortable(result R, err error) bool
func (*BaseAbortablePolicy[R]) IsConfigured ¶ added in v0.5.0
func (c *BaseAbortablePolicy[R]) IsConfigured() bool
type BaseDelayablePolicy ¶
BaseDelayablePolicy provides a base for implementing DelayablePolicyBuilder.
func (*BaseDelayablePolicy[R]) ComputeDelay ¶
func (d *BaseDelayablePolicy[R]) ComputeDelay(exec failsafe.ExecutionAttempt[R]) time.Duration
ComputeDelay returns a computed delay else -1 if no delay could be computed.
func (*BaseDelayablePolicy[R]) WithDelay ¶
func (d *BaseDelayablePolicy[R]) WithDelay(delay time.Duration)
func (*BaseDelayablePolicy[R]) WithDelayFunc ¶ added in v0.4.0
func (d *BaseDelayablePolicy[R]) WithDelayFunc(delayFunc failsafe.DelayFunc[R])
type BaseExecutor ¶
type BaseExecutor[R any] struct { Executor[R] *BaseFailurePolicy[R] }
BaseExecutor provides base implementation of Executor.
func (*BaseExecutor[R]) Apply ¶
func (e *BaseExecutor[R]) Apply(innerFn func(failsafe.Execution[R]) *common.PolicyResult[R]) func(failsafe.Execution[R]) *common.PolicyResult[R]
func (*BaseExecutor[R]) IsFailure ¶
func (e *BaseExecutor[R]) IsFailure(result R, err error) bool
func (*BaseExecutor[R]) OnFailure ¶
func (e *BaseExecutor[R]) OnFailure(exec ExecutionInternal[R], result *common.PolicyResult[R]) *common.PolicyResult[R]
func (*BaseExecutor[R]) OnSuccess ¶
func (e *BaseExecutor[R]) OnSuccess(exec ExecutionInternal[R], result *common.PolicyResult[R])
func (*BaseExecutor[R]) PostExecute ¶
func (e *BaseExecutor[R]) PostExecute(exec ExecutionInternal[R], er *common.PolicyResult[R]) *common.PolicyResult[R]
func (*BaseExecutor[R]) PreExecute ¶
func (e *BaseExecutor[R]) PreExecute(_ ExecutionInternal[R]) *common.PolicyResult[R]
type BaseFailurePolicy ¶
type BaseFailurePolicy[R any] struct { // contains filtered or unexported fields }
BaseFailurePolicy provides a base for implementing FailurePolicyBuilder.
func (*BaseFailurePolicy[R]) HandleErrorTypes ¶ added in v0.6.7
func (p *BaseFailurePolicy[R]) HandleErrorTypes(errs ...any)
func (*BaseFailurePolicy[R]) HandleErrors ¶
func (p *BaseFailurePolicy[R]) HandleErrors(errs ...error)
func (*BaseFailurePolicy[R]) HandleIf ¶
func (p *BaseFailurePolicy[R]) HandleIf(predicate func(R, error) bool)
func (*BaseFailurePolicy[R]) HandleResult ¶
func (p *BaseFailurePolicy[R]) HandleResult(result R)
func (*BaseFailurePolicy[R]) IsFailure ¶
func (p *BaseFailurePolicy[R]) IsFailure(result R, err error) bool
func (*BaseFailurePolicy[R]) OnFailure ¶
func (p *BaseFailurePolicy[R]) OnFailure(listener func(event failsafe.ExecutionEvent[R]))
func (*BaseFailurePolicy[R]) OnSuccess ¶
func (p *BaseFailurePolicy[R]) OnSuccess(listener func(event failsafe.ExecutionEvent[R]))
type ExecutionInternal ¶
type ExecutionInternal[R any] interface { failsafe.Execution[R] // RecordResult records an execution result, such as before a retry attempt, and returns the result or the cancel result, // if any. RecordResult(result *common.PolicyResult[R]) *common.PolicyResult[R] // InitializeRetry prepares a new execution retry. If the retry could not be initialized because was canceled, the associated // cancellation result is returned. InitializeRetry() *common.PolicyResult[R] // Cancel cancels the execution with the result. Cancel(result *common.PolicyResult[R]) // IsCanceledWithResult returns whether the execution is canceled, along with the cancellation result, if any. IsCanceledWithResult() (bool, *common.PolicyResult[R]) // CopyWithResult returns a copy of the failsafe.Execution with the result. If the result is nil, this will preserve a // copy of the lastResult and lastError. This is useful before passing the execution to an event listener, otherwise // these may be changed if the execution is canceled. CopyWithResult(result *common.PolicyResult[R]) failsafe.Execution[R] // CopyForCancellable creates a cancellable child copy of the execution based on the current execution's context. CopyForCancellable() failsafe.Execution[R] // CopyForHedge creates a copy of the execution marked as a hedge. CopyForHedge() failsafe.Execution[R] }
type Executor ¶
type Executor[R any] interface { // PreExecute is called before execution to return an alternative result or error, such as if execution is not allowed or // needed. PreExecute(exec ExecutionInternal[R]) *common.PolicyResult[R] // Apply performs an execution by calling PreExecute and returning any result, else calling the innerFn PostExecute. // // If an Executor delays or blocks during execution, it must check that the execution was not canceled in the // meantime, else return the ExecutionInternal.Result if it was. Apply(innerFn func(failsafe.Execution[R]) *common.PolicyResult[R]) func(failsafe.Execution[R]) *common.PolicyResult[R] // PostExecute performs synchronous post-execution handling for an execution result. PostExecute(exec ExecutionInternal[R], result *common.PolicyResult[R]) *common.PolicyResult[R] // IsFailure returns whether the result is a failure according to the corresponding policy. IsFailure(result R, err error) bool // OnSuccess performs post-execution handling for a result that is considered a success according to IsFailure. OnSuccess(exec ExecutionInternal[R], result *common.PolicyResult[R]) // OnFailure performs post-execution handling for a result that is considered a failure according to IsFailure, possibly // creating a new result, else returning the original result. OnFailure(exec ExecutionInternal[R], result *common.PolicyResult[R]) *common.PolicyResult[R] }
Executor handles execution and execution results according to a policy. May contain pre-execution and post-execution behaviors. Each Executor makes its own determination about whether an execution result is a success or failure.