Skip to content

Commit 821b132

Browse files
authored
changed http timeout and logged time elapsed to fetch data (#954)
1 parent 672ba2e commit 821b132

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

utils/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func (*UtilsStruct) GetDataFromAPI(url string) ([]byte, error) {
1414
client := http.Client{
15-
Timeout: 60 * time.Second,
15+
Timeout: 10 * time.Second,
1616
}
1717
var body []byte
1818
err := retry.Do(

utils/asset.go

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"razor/pkg/bindings"
1313
"regexp"
1414
"strconv"
15+
"time"
1516

1617
"github.com/avast/retry-go"
1718
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -273,11 +274,14 @@ func (*UtilsStruct) GetDataToCommitFromJob(job bindings.StructsJob) (*big.Int, e
273274
// Fetch data from API with retry mechanism
274275
var parsedData interface{}
275276
if job.SelectorType == 0 {
277+
start := time.Now()
276278
response, apiErr = UtilsInterface.GetDataFromAPI(job.Url)
277279
if apiErr != nil {
278280
log.Error("Error in fetching data from API: ", apiErr)
279281
return nil, apiErr
280282
}
283+
elapsed := time.Since(start).Seconds()
284+
log.Debugf("Time taken to fetch the data from API : %s was %f", job.Url, elapsed)
281285

282286
err := json.Unmarshal(response, &parsedJSON)
283287
if err != nil {

0 commit comments

Comments
 (0)