From 116cb0fa8e67508d8ecf9463a6f89cd0532cf316 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 19 Apr 2020 18:04:38 +0200 Subject: [PATCH] Limit retries for meter reading --- core/loadpoint.go | 10 +++------- go.mod | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 21fb854a24..9978e03073 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -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 diff --git a/go.mod b/go.mod index ac3779c3cc..67536c1ee7 100644 --- a/go.mod +++ b/go.mod @@ -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