mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
Use non-blocking send at close, use common done function and remove default case
This commit is contained in:
parent
babd7a9af8
commit
3fd77e6887
@ -2,12 +2,11 @@ package sinks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
// "log"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
||||||
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AvailableSinks = map[string]Sink{
|
var AvailableSinks = map[string]Sink{
|
||||||
@ -67,16 +66,18 @@ func (sm *sinkManager) Start() {
|
|||||||
sm.wg.Add(1)
|
sm.wg.Add(1)
|
||||||
batchcount := 20
|
batchcount := 20
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
done := func() {
|
||||||
SinkManagerLoop:
|
|
||||||
select {
|
|
||||||
case <-sm.done:
|
|
||||||
for _, s := range sm.outputs {
|
for _, s := range sm.outputs {
|
||||||
s.Close()
|
s.Close()
|
||||||
}
|
}
|
||||||
cclog.ComponentDebug("SinkManager", "DONE")
|
cclog.ComponentDebug("SinkManager", "DONE")
|
||||||
sm.wg.Done()
|
sm.wg.Done()
|
||||||
break SinkManagerLoop
|
}
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-sm.done:
|
||||||
|
done()
|
||||||
|
return
|
||||||
case p := <-sm.input:
|
case p := <-sm.input:
|
||||||
cclog.ComponentDebug("SinkManager", "WRITE", p)
|
cclog.ComponentDebug("SinkManager", "WRITE", p)
|
||||||
for _, s := range sm.outputs {
|
for _, s := range sm.outputs {
|
||||||
@ -90,7 +91,6 @@ func (sm *sinkManager) Start() {
|
|||||||
batchcount = 20
|
batchcount = 20
|
||||||
}
|
}
|
||||||
batchcount--
|
batchcount--
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -128,7 +128,10 @@ func (sm *sinkManager) AddOutput(rawConfig json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sm *sinkManager) Close() {
|
func (sm *sinkManager) Close() {
|
||||||
sm.done <- true
|
select {
|
||||||
|
case sm.done <- true:
|
||||||
|
default:
|
||||||
|
}
|
||||||
cclog.ComponentDebug("SinkManager", "CLOSE")
|
cclog.ComponentDebug("SinkManager", "CLOSE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user