mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-07-20 03:41:42 +02:00
Use two separate inputs for metric router to simplify management. Activate --logfile option and close MultiChanTicker explicitly
This commit is contained in:
@@ -1,27 +1,43 @@
|
||||
package multiChanTicker
|
||||
|
||||
import (
|
||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
||||
"time"
|
||||
)
|
||||
|
||||
type multiChanTicker struct {
|
||||
ticker *time.Ticker
|
||||
channels []chan time.Time
|
||||
done chan bool
|
||||
}
|
||||
|
||||
type MultiChanTicker interface {
|
||||
Init(duration time.Duration)
|
||||
AddChannel(chan time.Time)
|
||||
Close()
|
||||
}
|
||||
|
||||
func (t *multiChanTicker) Init(duration time.Duration) {
|
||||
t.ticker = time.NewTicker(duration)
|
||||
t.done = make(chan bool)
|
||||
go func() {
|
||||
done := func() {
|
||||
cclog.ComponentDebug("MultiChanTicker", "DONE")
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-t.done:
|
||||
done()
|
||||
return
|
||||
case ts := <-t.ticker.C:
|
||||
cclog.ComponentDebug("MultiChanTicker", "Tick", ts)
|
||||
for _, c := range t.channels {
|
||||
c <- ts
|
||||
select {
|
||||
case <-t.done:
|
||||
done()
|
||||
return
|
||||
case c <- ts:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +48,11 @@ func (t *multiChanTicker) AddChannel(channel chan time.Time) {
|
||||
t.channels = append(t.channels, channel)
|
||||
}
|
||||
|
||||
func (t *multiChanTicker) Close() {
|
||||
t.done <- true
|
||||
cclog.ComponentDebug("MultiChanTicker", "CLOSE")
|
||||
}
|
||||
|
||||
func NewTicker(duration time.Duration) MultiChanTicker {
|
||||
t := &multiChanTicker{}
|
||||
t.Init(duration)
|
||||
|
Reference in New Issue
Block a user