Skip to content

Commit

Permalink
Added client retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortejoso committed Dec 19, 2024
1 parent ab96f20 commit bcaa81d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions compat_test/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,23 @@ func fetchBlockElementsWithRetry(clients *clients, blockNumber uint64, resultCha
}, 5, time.Minute*2)
}

func retryOperation(ctx context.Context, operation func() error, retries int, delay time.Duration) error {
var err error
for i := 0; i < retries; i++ {
err = operation()
if err == nil {
return nil
}
fmt.Printf("Retry %d/%d failed: %v\n", i+1, retries, err)
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(delay):
}
}
return fmt.Errorf("operation failed after %d retries: %w", retries, err)
}

func jsonConvert(in, out any) error {
marshaled, err := json.Marshal(in)
if err != nil {
Expand Down

0 comments on commit bcaa81d

Please sign in to comment.