File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,10 @@ func NewWriterWithTopic(topic topic.Topic) *Writer {
5656 }
5757}
5858
59+ func (w * Writer ) Close () {
60+ w .Close ()
61+ }
62+
5963func (w * Writer ) WriteEvent (e interface {}) {
6064 w .WriteEventWithTimestamp (e , time .Now ())
6165}
Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ func Run() error {
112112
113113 // Ensure all workflow plugins are destroyed before core teardown
114114 integration .PluginsInstance ().DestroyAll ()
115+ the .ClearEventWriters ()
115116
116117 return err
117118}
Original file line number Diff line number Diff line change 2525package the
2626
2727import (
28+ "sync"
29+
2830 "github.com/AliceO2Group/Control/common/event"
2931 "github.com/AliceO2Group/Control/common/event/topic"
32+ "github.com/AliceO2Group/Control/common/logger"
33+ "github.com/sirupsen/logrus"
34+ )
35+
36+ var (
37+ writers = make (map [topic.Topic ]* event.Writer )
38+ mu sync.Mutex
39+ log = logger .New (logrus .StandardLogger (), "core" )
3040)
3141
42+ func createOrGetWriter (topic topic.Topic ) * event.Writer {
43+ mu .Lock ()
44+ defer mu .Unlock ()
45+
46+ if writer , ok := writers [topic ]; ok {
47+ return writer
48+ }
49+
50+ writers [topic ] = event .NewWriterWithTopic (topic )
51+ return writers [topic ]
52+ }
53+
3254func EventWriter () * event.Writer {
33- return EventWriterWithTopic (topic .Root )
55+ return createOrGetWriter (topic .Root )
3456}
3557
3658func EventWriterWithTopic (topic topic.Topic ) * event.Writer {
37- return event .NewWriterWithTopic (topic )
59+ return createOrGetWriter (topic )
60+ }
61+
62+ func ClearEventWriters () {
63+ mu .Lock ()
64+ defer mu .Unlock ()
65+
66+ log .Logf (logrus .InfoLevel , "Clearing %d kafka producers" , len (writers ))
67+ for _ , writer := range writers {
68+ writer .Close ()
69+ }
70+ clear (writers )
3871}
You can’t perform that action at this time.
0 commit comments