Delay download of historical tickers by one hour
If the download is initiated too early, the provider does not yet have the historical tokens ready.
This commit is contained in:
parent
f24c83b33a
commit
3932d19707
@ -105,7 +105,7 @@ func (cg *Coingecko) makeReq(url string) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// if there is a throttling error, wait 60 seconds and retry
|
// if there is a throttling error, wait 60 seconds and retry
|
||||||
glog.Errorf("Coingecko makeReq %v error %v, will retry in 60 seconds", url, err)
|
glog.Warningf("Coingecko makeReq %v error %v, will retry in 60 seconds", url, err)
|
||||||
time.Sleep(60 * time.Second)
|
time.Sleep(60 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,7 +95,9 @@ func (rd *RatesDownloader) Run() error {
|
|||||||
rd.callbackOnNewTicker(tickers)
|
rd.callbackOnNewTicker(tickers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if time.Now().UTC().YearDay() != lastHistoricalTickers.YearDay() || time.Now().UTC().Year() != lastHistoricalTickers.Year() {
|
now := time.Now().UTC()
|
||||||
|
// once a day, 1 hour after UTC midnight (to let the provider prepare historical rates) update historical tickers
|
||||||
|
if (now.YearDay() != lastHistoricalTickers.YearDay() || now.Year() != lastHistoricalTickers.Year()) && now.Hour() > 0 {
|
||||||
err = rd.downloader.UpdateHistoricalTickers()
|
err = rd.downloader.UpdateHistoricalTickers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("FiatRatesDownloader: UpdateHistoricalTickers error ", err)
|
glog.Error("FiatRatesDownloader: UpdateHistoricalTickers error ", err)
|
||||||
@ -127,10 +129,10 @@ func (rd *RatesDownloader) Run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wait for the next run with a slight random value to avoid too many request at the same time
|
// wait for the next run with a slight random value to avoid too many request at the same time
|
||||||
now := time.Now().Unix()
|
unix := time.Now().Unix()
|
||||||
next := now + rd.periodSeconds
|
next := unix + rd.periodSeconds
|
||||||
next -= next % rd.periodSeconds
|
next -= next % rd.periodSeconds
|
||||||
next += int64(rand.Intn(12))
|
next += int64(rand.Intn(12))
|
||||||
time.Sleep(time.Duration(next-now) * time.Second)
|
time.Sleep(time.Duration(next-unix) * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user