Enever: avoid hitting rate limit (#18731)

This commit is contained in:
andig 2025-02-11 09:24:40 +01:00 • committed by GitHub
parent b9dc1454d6
commit b8924cd6a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -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()

View file

@ -69,3 +69,4 @@ render: |
"price": .prijs{{ .provider }} | tonumber
}
] | tostring
interval: 3h