Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExponentialBackoff ¶
type ExponentialBackoff struct { // MaxRetries is the amount of retry which is allowed before giving up the application. // // Default: 5 MaxRetries int // BackoffDuration is the time duration which will be used to calculate the exponential backoff wait time. // // Default: 1/2 Second BackoffDuration time.Duration }
ExponentialBackoff will answer if retry can be made. It waits as well the amount of time based on the failure count. The waiting time before returning is doubled for each failed attempts This ensures that the system gets progressively more time to recover from any issues.
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/retry" ) func main() { ctx := context.Background() rs := retry.ExponentialBackoff{} for i := 0; rs.ShouldTry(ctx, i); i++ { // do an action // return on success } // return failure }
func (ExponentialBackoff) ShouldTry ¶
func (rs ExponentialBackoff) ShouldTry(ctx context.Context, count FailureCount) bool
type FailureCount ¶ added in v0.176.0
type FailureCount = int
type Jitter ¶
type Jitter struct { // MaxRetries is the amount of retry that is allowed before giving up the application. // // Default: 5 MaxRetries int // MaxWaitDuration is the duration the Jitter will maximum wait between two retries. // // Default: 5 Second MaxWaitDuration time.Duration }
Jitter is a random variation added to the backoff time. This helps to distribute the retry attempts evenly over time, reducing the risk of overwhelming the system and avoiding synchronization between multiple clients that might be retrying simultaneously.
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/retry" ) func main() { ctx := context.Background() rs := retry.Jitter{} for i := 0; rs.ShouldTry(ctx, i); i++ { // do an action // return on success } // return failure }
type Strategy ¶
type Strategy[U StrategyUnit] interface { // ShouldTry will tell if retry should be attempted after a given number of failed attempts. ShouldTry(ctx context.Context, u U) bool }
type StrategyUnit ¶ added in v0.176.0
type StrategyUnit interface{ FailureCount | StartedAt }
type Waiter ¶ added in v0.176.0
type Waiter struct { // Timeout refers to the maximum duration we can wait // before a retry attempt is deemed unreasonable. // // Default: 30 seconds Timeout time.Duration }
func (Waiter) ShouldTry ¶ added in v0.176.0
Example ¶
package main import ( "context" "go.llib.dev/frameless/pkg/retry" "time" ) func main() { var ( ctx = context.Background() rs = retry.Waiter{Timeout: time.Minute} now = time.Now() ) for rs.ShouldTry(ctx, now) { // do an action // return on success } // return failure }
Click to show internal directories.
Click to hide internal directories.