-
Notifications
You must be signed in to change notification settings - Fork 7
/
broadcast.go
45 lines (38 loc) · 1.17 KB
/
broadcast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package repo
import (
"time"
"github.com/flomesh-io/fsm/pkg/announcements"
)
// BroadcastListener listens for broadcast messages from the message broker
func (s *Server) BroadcastListener() {
// Register for proxy config updates broadcast by the message broker
ingressUpdatePubSub := s.msgBroker.GetIngressUpdatePubSub()
ingressUpdateChan := ingressUpdatePubSub.Sub(announcements.IngressUpdate.String())
defer s.msgBroker.Unsub(ingressUpdatePubSub, ingressUpdateChan)
// Wait for two informer synchronization periods
slidingTimer := time.NewTimer(time.Second * 20)
defer slidingTimer.Stop()
reconfirm := true
for {
select {
case <-ingressUpdateChan:
// Wait for an informer synchronization period
slidingTimer.Reset(time.Second * 5)
// Avoid data omission
reconfirm = true
case <-slidingTimer.C:
//metricsstore.DefaultMetricsStore.ProxyConnectCount.Set(float64(len(proxies)))
newJob := func() *IngressConfGeneratorJob {
return &IngressConfGeneratorJob{
cache: s.cache,
done: make(chan struct{}),
}
}
<-s.workQueues.AddJob(newJob())
if reconfirm {
reconfirm = false
slidingTimer.Reset(time.Second * 10)
}
}
}
}