Enever: avoid hitting rate limit (#18731)
This commit is contained in:
parent
b9dc1454d6
commit
b8924cd6a9
2 changed files with 7 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -69,3 +69,4 @@ render: |
|
|||
"price": .prijs{{ .provider }} | tonumber
|
||||
}
|
||||
] | tostring
|
||||
interval: 3h
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue