Skip to content

Commit

Permalink
fix the retry functions
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichwilken committed Dec 16, 2024
1 parent 72d52b1 commit 8a9e600
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions e2e/common/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ func Retry(attempts int, interval time.Duration, fn func() error) error {
ticker := time.NewTicker(interval)
defer ticker.Stop()
var err error
for range ticker.C {
attempts--
err = fn()
if err == nil || attempts == 0 {
return err
for attempts > 0 {
select {
case <-ticker.C:
attempts--
err = fn()
if err == nil {
return err
}
}
}
// Return nil if all attempts fail.
Expand All @@ -24,11 +27,15 @@ func RetryGet[T any](attempts int, interval time.Duration, fn func() (*T, error)
defer ticker.Stop()
var err error
var obj *T
for range ticker.C {
attempts--
obj, err = fn()
if err == nil || attempts == 0 {
return obj, err
for
for attempts > 0 {

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

syntax error: unexpected for, expected expression (typecheck)

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

expected operand, found 'for' (typecheck)

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected operand, found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected ';', found '{'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected operand, found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected ';', found '{'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected operand, found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected ';', found '{'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected operand, found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected ';', found '{'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected operand, found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected ';', found '{'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected '{', found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected operand, found 'for'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected ';', found '{'

Check failure on line 31 in e2e/common/retry.go

View workflow job for this annotation

GitHub Actions / e2e-upgrade

expected '{', found 'for'
select {
case <-ticker.C:
attempts--
obj, err = fn()
if err == nil {
return obj, err
}
}
}
// Return nil object if all attempts fail.
Expand Down

0 comments on commit 8a9e600

Please sign in to comment.