fix: properly setup collectible providers exponential backoff
This commit is contained in:
parent
168398d7a5
commit
9fef2d3558
|
@ -129,14 +129,13 @@ func (o *Client) doPostWithJSON(ctx context.Context, url string, payload any) (*
|
|||
}
|
||||
|
||||
func (o *Client) doWithRetries(req *http.Request) (*http.Response, error) {
|
||||
b := backoff.ExponentialBackOff{
|
||||
InitialInterval: time.Millisecond * 1000,
|
||||
RandomizationFactor: 0.1,
|
||||
Multiplier: 1.5,
|
||||
MaxInterval: time.Second * 32,
|
||||
MaxElapsedTime: time.Second * 128,
|
||||
Clock: backoff.SystemClock,
|
||||
}
|
||||
b := backoff.NewExponentialBackOff()
|
||||
b.InitialInterval = time.Millisecond * 1000
|
||||
b.RandomizationFactor = 0.1
|
||||
b.Multiplier = 1.5
|
||||
b.MaxInterval = time.Second * 32
|
||||
b.MaxElapsedTime = time.Second * 70
|
||||
|
||||
b.Reset()
|
||||
|
||||
op := func() (*http.Response, error) {
|
||||
|
@ -151,12 +150,13 @@ func (o *Client) doWithRetries(req *http.Request) (*http.Response, error) {
|
|||
|
||||
err = fmt.Errorf("unsuccessful request: %d %s", resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
if resp.StatusCode == http.StatusTooManyRequests {
|
||||
log.Error("doWithRetries failed with http.StatusTooManyRequests", "provider", o.ID(), "elapsed time", b.GetElapsedTime(), "next backoff", b.NextBackOff())
|
||||
return nil, err
|
||||
}
|
||||
return nil, backoff.Permanent(err)
|
||||
}
|
||||
|
||||
return backoff.RetryWithData(op, &b)
|
||||
return backoff.RetryWithData(op, b)
|
||||
}
|
||||
|
||||
func (o *Client) FetchCollectibleOwnersByContractAddress(ctx context.Context, chainID walletCommon.ChainID, contractAddress common.Address) (*thirdparty.CollectibleContractOwnership, error) {
|
||||
|
|
|
@ -157,7 +157,9 @@ func (o *ClientV2) fetchAssets(ctx context.Context, chainID walletCommon.ChainID
|
|||
|
||||
body, err := o.client.doGetRequest(ctx, url, o.apiKey)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
o.connectionStatus.SetIsConnected(false)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
o.connectionStatus.SetIsConnected(true)
|
||||
|
@ -274,7 +276,9 @@ func (o *ClientV2) fetchCollectionDataBySlug(ctx context.Context, chainID wallet
|
|||
|
||||
body, err := o.client.doGetRequest(ctx, url, o.apiKey)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
o.connectionStatus.SetIsConnected(false)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
o.connectionStatus.SetIsConnected(true)
|
||||
|
|
|
@ -143,14 +143,13 @@ func (o *Client) doPostWithJSON(ctx context.Context, url string, payload any, ap
|
|||
}
|
||||
|
||||
func (o *Client) doWithRetries(req *http.Request, apiKey string) (*http.Response, error) {
|
||||
b := backoff.ExponentialBackOff{
|
||||
InitialInterval: time.Millisecond * 1000,
|
||||
RandomizationFactor: 0.1,
|
||||
Multiplier: 1.5,
|
||||
MaxInterval: time.Second * 32,
|
||||
MaxElapsedTime: time.Second * 128,
|
||||
Clock: backoff.SystemClock,
|
||||
}
|
||||
b := backoff.NewExponentialBackOff()
|
||||
b.InitialInterval = time.Millisecond * 1000
|
||||
b.RandomizationFactor = 0.1
|
||||
b.Multiplier = 1.5
|
||||
b.MaxInterval = time.Second * 32
|
||||
b.MaxElapsedTime = time.Second * 70
|
||||
|
||||
b.Reset()
|
||||
|
||||
req.Header.Set("X-API-KEY", apiKey)
|
||||
|
@ -167,12 +166,13 @@ func (o *Client) doWithRetries(req *http.Request, apiKey string) (*http.Response
|
|||
|
||||
err = fmt.Errorf("unsuccessful request: %d %s", resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
if resp.StatusCode == http.StatusTooManyRequests {
|
||||
log.Error("doWithRetries failed with http.StatusTooManyRequests", "provider", o.ID(), "elapsed time", b.GetElapsedTime(), "next backoff", b.NextBackOff())
|
||||
return nil, err
|
||||
}
|
||||
return nil, backoff.Permanent(err)
|
||||
}
|
||||
|
||||
return backoff.RetryWithData(op, &b)
|
||||
return backoff.RetryWithData(op, b)
|
||||
}
|
||||
|
||||
func (o *Client) FetchCollectibleOwnersByContractAddress(ctx context.Context, chainID walletCommon.ChainID, contractAddress common.Address) (*thirdparty.CollectibleContractOwnership, error) {
|
||||
|
@ -197,7 +197,9 @@ func (o *Client) FetchCollectibleOwnersByContractAddress(ctx context.Context, ch
|
|||
|
||||
resp, err := o.doQuery(ctx, url, o.getAPIKey(chainID))
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
o.connectionStatus.SetIsConnected(false)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
o.connectionStatus.SetIsConnected(true)
|
||||
|
@ -258,7 +260,9 @@ func (o *Client) FetchAllAssetsByOwner(ctx context.Context, chainID walletCommon
|
|||
|
||||
resp, err := o.doQuery(ctx, url, o.getAPIKey(chainID))
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
o.connectionStatus.SetIsConnected(false)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
o.connectionStatus.SetIsConnected(true)
|
||||
|
@ -398,7 +402,9 @@ func (o *Client) FetchCollectionsDataByContractID(ctx context.Context, contractI
|
|||
|
||||
resp, err := o.doQuery(ctx, url, o.getAPIKey(contractID.ChainID))
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
o.connectionStatus.SetIsConnected(false)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
o.connectionStatus.SetIsConnected(true)
|
||||
|
|
Loading…
Reference in New Issue