Per-host circuit breaker с retry для CDN fetch и RIPEstat; порог 5 ошибок, cooldown 30s. Co-authored-by: Cursor <[email protected]>
24 lines
471 B
Go
24 lines
471 B
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"evobgp/internal/httpclient"
|
|
)
|
|
|
|
func upstreamHTTPDo(ctx context.Context, hc *http.Client, req *http.Request) (*http.Response, error) {
|
|
if hc == nil {
|
|
hc = httpclient.New(httpclient.DefaultTimeout)
|
|
}
|
|
resp, err := httpclient.DoWithBreaker(ctx, hc, req, 3)
|
|
if err != nil {
|
|
if req.URL != nil {
|
|
return nil, fmt.Errorf("cdn fetch %s: %w", req.URL.String(), err)
|
|
}
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
}
|