From b8924cd6a970c53bd03f9a3fc3111ae808db8aa2 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 11 Feb 2025 09:24:40 +0100 Subject: [PATCH] Enever: avoid hitting rate limit (#18731) --- tariff/tariff.go | 10 ++++++---- templates/definition/tariff/enever.yaml | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tariff/tariff.go b/tariff/tariff.go index 783db9aa8..c761e7ff7 100644 --- a/tariff/tariff.go +++ b/tariff/tariff.go @@ -35,9 +35,11 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{} Price *plugin.Config Forecast *plugin.Config Type api.TariffType `mapstructure:"tariff"` + Interval time.Duration Cache time.Duration }{ - Cache: 15 * time.Minute, + Interval: time.Hour, + Cache: 15 * time.Minute, } if err := util.DecodeOther(other, &cc); err != nil { @@ -75,17 +77,17 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{} if forecastG != nil { done := make(chan error) - go t.run(forecastG, done) + go t.run(forecastG, done, cc.Interval) err = <-done } return t, err } -func (t *Tariff) run(forecastG func() (string, error), done chan error) { +func (t *Tariff) run(forecastG func() (string, error), done chan error, interval time.Duration) { var once sync.Once - for tick := time.Tick(time.Hour); ; <-tick { + for tick := time.Tick(interval); ; <-tick { var data api.Rates if err := backoff.Retry(func() error { s, err := forecastG() diff --git a/templates/definition/tariff/enever.yaml b/templates/definition/tariff/enever.yaml index 697a0099c..5d6caa86a 100644 --- a/templates/definition/tariff/enever.yaml +++ b/templates/definition/tariff/enever.yaml @@ -69,3 +69,4 @@ render: | "price": .prijs{{ .provider }} | tonumber } ] | tostring + interval: 3h