converge/cmd/converge/notifier.go
Erik Brakkee db094d2a13 reverted changes to throttler for ignoring duplicate events. This caused
more problems since state is immutable but some state of agents and
client is not immutable so it ignored events that were not really
duplicates.
This reverts commit f6b0211336.
2024-09-08 11:16:49 +02:00

30 lines
858 B
Go

package main
import (
"git.wamblee.org/converge/pkg/models"
"git.wamblee.org/converge/pkg/support/throttling"
"time"
)
type StateNotifier struct {
throttler *throttling.AsyncThrottler[models.State]
webNotificationChannel chan *models.State
prometheusNotificationChannel chan *models.State
}
func NewStateNotifier(minDelay time.Duration) *StateNotifier {
notifier := StateNotifier{
webNotificationChannel: make(chan *models.State),
prometheusNotificationChannel: make(chan *models.State),
}
notifier.throttler = throttling.NewAsyncThrottler(func(state *models.State) {
notifier.webNotificationChannel <- state
notifier.prometheusNotificationChannel <- state
}, minDelay, 1*time.Second)
return &notifier
}
func (notifier StateNotifier) Publish(state *models.State) {
notifier.throttler.Notify(state)
}