Skip to content

Commit

Permalink
fix: gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikelle committed Nov 7, 2024
1 parent 1a54590 commit 52f9c6a
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions cl/redisapp/util/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@ func RetryWithBackoff(ctx context.Context, maxAttempts uint64, log *slog.Logger,
}

func RetryWithInfiniteBackoff(ctx context.Context, log *slog.Logger, operation func() error) error {
eb := backoff.NewExponentialBackOff()
eb.InitialInterval = initialBackoff
eb.MaxInterval = maxBackoff
eb.MaxElapsedTime = 0 // Infinite retry
eb := backoff.NewExponentialBackOff()
eb.InitialInterval = initialBackoff
eb.MaxInterval = maxBackoff
eb.MaxElapsedTime = 0 // Infinite retry

err := backoff.Retry(func() error {
select {
case <-ctx.Done():
log.Info("Context canceled, stopping retries.")
return backoff.Permanent(ctx.Err())
default:
err := operation()
if err != nil {
// Log and retry unless it's a permanent error
log.Warn("Operation failed, will retry", "error", err)
return err
}
return nil // Success
}
}, backoff.WithContext(eb, ctx))
err := backoff.Retry(func() error {
select {
case <-ctx.Done():
log.Info("Context canceled, stopping retries.")
return backoff.Permanent(ctx.Err())
default:
err := operation()
if err != nil {
// Log and retry unless it's a permanent error
log.Warn("Operation failed, will retry", "error", err)
return err
}
return nil // Success
}
}, backoff.WithContext(eb, ctx))

if err != nil {
return fmt.Errorf("operation failed: %w", err)
}
return nil
if err != nil {
return fmt.Errorf("operation failed: %w", err)
}
return nil
}

0 comments on commit 52f9c6a

Please sign in to comment.