Skip to content

Commit

Permalink
changed http timeout and logged time elapsed to fetch data (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashk767 authored Sep 29, 2022
1 parent 672ba2e commit 821b132
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func (*UtilsStruct) GetDataFromAPI(url string) ([]byte, error) {
client := http.Client{
Timeout: 60 * time.Second,
Timeout: 10 * time.Second,
}
var body []byte
err := retry.Do(
Expand Down
4 changes: 4 additions & 0 deletions utils/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"razor/pkg/bindings"
"regexp"
"strconv"
"time"

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

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

0 comments on commit 821b132

Please sign in to comment.