Skip to content

Commit

Permalink
internal.Retry takes into account the last delay for considering heal…
Browse files Browse the repository at this point in the history
…thy lifetimes
  • Loading branch information
Danlock committed Oct 14, 2023
1 parent 26c1de3 commit 6f6aafc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func (l AMQP091Logger) Printf(format string, v ...interface{}) {
const healthyLifetime = 20 * time.Millisecond

// Retry attempts do repeatedly until it's ctx ends. If do returns false delayForAttempt is used to backoff retries.
// If do is true and ran longer than healthyLifetime the backoff is reset. do returns it's own lifetime, since it may do some setup beforehand.
// If do is true and ran longer than healthyLifetime or it's last delay the backoff is reset. do returns it's own lifetime, since it may do some setup beforehand.
func Retry(ctx context.Context, delayForAttempt func(int) time.Duration, do func(time.Duration) (time.Duration, bool)) {
var delay time.Duration
var attempt = 0
for {
delay = delayForAttempt(attempt)
attempt++
lifetime, ok := do(delay)
if ok && lifetime >= healthyLifetime {
if ok && lifetime >= max(healthyLifetime, delay) {
delay, attempt = 0, 0
}

Expand Down

0 comments on commit 6f6aafc

Please sign in to comment.