Limit retries for meter reading

This commit is contained in:
andig 2020-04-19 18:04:38 +02:00
parent e50cac2161
commit 116cb0fa8e
2 changed files with 4 additions and 8 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/andig/evcc/api"
"github.com/andig/evcc/core/wrapper"
"github.com/andig/evcc/push"
"github.com/pkg/errors"
evbus "github.com/asaskevich/EventBus"
"github.com/avast/retry-go"
@ -437,19 +438,14 @@ func (lp *LoadPoint) updateMeter(name string, meter api.Meter, power *float64) e
// updateMeter updates and publishes single meter
func (lp *LoadPoint) updateMeters() (err error) {
// var wg sync.WaitGroup
// var mux sync.Mutex
retry := func(s string, m api.Meter, f *float64) {
e := retry.Do(func() error {
return lp.updateMeter(s, m, f)
})
}, retry.Attempts(3))
if e != nil {
err = errors.Wrapf(e, "updating %s meter", s)
log.ERROR.Printf("%s %v", lp.Name, err)
// mux.Lock()
err = e
// mux.Unlock()
}
// wg.Done()
}
// read PV meter before charge meter

2
go.mod
View file

@ -26,7 +26,7 @@ require (
github.com/mitchellh/mapstructure v1.2.2
github.com/mjibson/esc v0.2.0
github.com/pelletier/go-toml v1.7.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0