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.
30 lines
858 B
Go
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 ¬ifier
|
|
}
|
|
|
|
func (notifier StateNotifier) Publish(state *models.State) {
|
|
notifier.throttler.Notify(state)
|
|
}
|