chore: simplify
This commit is contained in:
parent
6e0867ac3e
commit
ceb5777849
1 changed files with 10 additions and 13 deletions
|
|
@ -76,26 +76,23 @@ func (t *Ngeso) run(done chan error) {
|
|||
|
||||
// Data updated by ESO every half hour, but we only need data every hour to stay current.
|
||||
for ; true; <-time.Tick(time.Hour) {
|
||||
var carbonResponse ngeso.CarbonForecastResponse
|
||||
if err := backoff.Retry(func() error {
|
||||
var err error
|
||||
carbonResponse, err = tReq.DoRequest(client)
|
||||
|
||||
// Consider whether errors.As would be more appropriate if this needs to start dealing with wrapped errors.
|
||||
if se, ok := err.(request.StatusError); ok && se.HasStatus(http.StatusBadRequest) {
|
||||
// Catch cases where we're sending completely incorrect data (usually the result of a bad region).
|
||||
return backoff.Permanent(se)
|
||||
res, err := backoff.RetryWithData(func() (ngeso.CarbonForecastResponse, error) {
|
||||
res, err := tReq.DoRequest(client)
|
||||
var se request.StatusError
|
||||
if errors.As(err, &se) && se.HasStatus(http.StatusBadRequest) {
|
||||
return nil, backoff.Permanent(se)
|
||||
}
|
||||
return err
|
||||
}, bo); err != nil {
|
||||
return res, err
|
||||
}, bo)
|
||||
if err != nil {
|
||||
once.Do(func() { done <- err })
|
||||
|
||||
t.log.ERROR.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
data := make(api.Rates, 0, len(carbonResponse.Results()))
|
||||
for _, r := range carbonResponse.Results() {
|
||||
data := make(api.Rates, 0, len(res.Results()))
|
||||
for _, r := range res.Results() {
|
||||
ar := api.Rate{
|
||||
Start: r.ValidityStart.Time,
|
||||
End: r.ValidityEnd.Time,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue