ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

seperate func for is retriable (#441)

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
4929eb6c 9cfc831e

+22 -17
+22 -17
internal/brightdata/proxy.go
··· 71 71 return withRetries(client), nil 72 72 } 73 73 74 + var _ retryablehttp.LeveledLogger = slog.Default() 75 + 76 + // retrying 5xx errors and network errors, but not context cancellations or 4xx errors. 77 + func retriable(ctx context.Context, resp *http.Response, err error) (bool, error) { 78 + if ctx.Err() != nil { 79 + return false, ctx.Err() 80 + } 81 + if err != nil { 82 + return true, err // retry these as theya re non canceled? 83 + } 84 + if resp == nil || resp.Request == nil { 85 + return false, nil 86 + } 87 + switch resp.Request.Method { 88 + case http.MethodGet, http.MethodHead: 89 + default: 90 + return false, nil 91 + } 92 + return resp.StatusCode >= http.StatusInternalServerError && resp.StatusCode <= 599, nil 93 + } 94 + 74 95 func withRetries(baseClient *http.Client) *http.Client { 75 96 retryClient := retryablehttp.NewClient() 76 97 retryClient.HTTPClient = baseClient ··· 79 100 // Keep the library defaults for now: 80 101 // RetryMax=4, RetryWaitMin=1s, RetryWaitMax=30s, Backoff=DefaultBackoff. 81 102 // We'll tune these once we have a clearer sense of how often these retries fire. 82 - retryClient.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) { 83 - if ctx.Err() != nil { 84 - return false, ctx.Err() 85 - } 86 - if err != nil { 87 - return true, err // retry these as theya re non canceled? 88 - } 89 - if resp == nil || resp.Request == nil { 90 - return false, nil 91 - } 92 - switch resp.Request.Method { 93 - case http.MethodGet, http.MethodHead: 94 - default: 95 - return false, nil 96 - } 97 - return resp.StatusCode >= http.StatusInternalServerError && resp.StatusCode <= 599, nil 98 - } 103 + retryClient.CheckRetry = retriable 99 104 return retryClient.StandardClient() 100 105 } 101 106