@@ -13,6 +13,7 @@ import (
1313 "strings"
1414 "time"
1515
16+ "github.com/codeGROOVE-dev/retry"
1617 "github.com/ready-to-review/turnclient/pkg/turn"
1718)
1819
@@ -54,13 +55,31 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
5455 log .Printf ("Cache miss for %s, fetching from Turn API" , url )
5556 }
5657
57- // Just try once with timeout - if Turn API fails, it's not critical
58- turnCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
59- defer cancel ()
58+ // Use exponential backoff with jitter for Turn API calls
59+ var data * turn.CheckResponse
60+ err := retry .Do (func () error {
61+ // Create timeout context for Turn API call
62+ turnCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
63+ defer cancel ()
6064
61- data , err := app .turnClient .Check (turnCtx , url , app .currentUser .GetLogin (), updatedAt )
65+ var retryErr error
66+ data , retryErr = app .turnClient .Check (turnCtx , url , app .currentUser .GetLogin (), updatedAt )
67+ if retryErr != nil {
68+ log .Printf ("Turn API error (will retry): %v" , retryErr )
69+ return retryErr
70+ }
71+ return nil
72+ },
73+ retry .Attempts (maxRetries ),
74+ retry .DelayType (retry .BackOffDelay ),
75+ retry .MaxDelay (maxRetryDelay ),
76+ retry .OnRetry (func (n uint , err error ) {
77+ log .Printf ("Turn API retry %d/%d for %s: %v" , n + 1 , maxRetries , url , err )
78+ }),
79+ retry .Context (ctx ),
80+ )
6281 if err != nil {
63- log .Printf ("Turn API error (will use PR without metadata): %v" , err )
82+ log .Printf ("Turn API error after %d retries (will use PR without metadata): %v" , maxRetries , err )
6483 return nil , err
6584 }
6685
0 commit comments