-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Libbeat: wait for publisher and outputers to finish (i.e. proper shut…
…down) Libbeat publisher now exits once all async events are published, all events outputed and ConnectionModes closed. * Move WorkerSignal to libbeat/common: WorkerSignals are used in packages publisher and outputs * Add a second WaitGroup to WorkerSignal. WaitGroups are used to track events and shutdown of Go routines * Add methods in WorkerSignal that wrap WaitGroups methods call * Remove TestMessageWorkerStopQueue and stopQueue function in WorkerSignal: events are not considered failed at shutdown anymore * Add tests for published events after shutdown * Add method Close to outputs/Outputer. The method is called by publisher/outputWorker onStop() * Edit CHANGELOG
- Loading branch information
Showing
24 changed files
with
302 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package common | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// WorkerSignal ensure all events have been | ||
// treated before closing Go routines | ||
type WorkerSignal struct { | ||
Done chan struct{} | ||
wgEvent sync.WaitGroup | ||
wgWorker sync.WaitGroup | ||
} | ||
|
||
func NewWorkerSignal() *WorkerSignal { | ||
w := &WorkerSignal{} | ||
w.Init() | ||
return w | ||
} | ||
|
||
func (ws *WorkerSignal) Init() { | ||
ws.Done = make(chan struct{}) | ||
} | ||
|
||
func (ws *WorkerSignal) AddEvent(delta int) { | ||
ws.wgEvent.Add(delta) | ||
} | ||
|
||
func (ws *WorkerSignal) DoneEvent() { | ||
ws.wgEvent.Done() | ||
} | ||
|
||
func (ws *WorkerSignal) WorkerStart() { | ||
ws.wgWorker.Add(1) | ||
} | ||
|
||
func (ws *WorkerSignal) WorkerFinished() { | ||
ws.wgWorker.Done() | ||
} | ||
|
||
func (ws *WorkerSignal) Stop() { | ||
ws.wgEvent.Wait() // Wait for all events to be dealt with | ||
close(ws.Done) // Ask Go routines to exit | ||
ws.wgWorker.Wait() // Wait for Go routines to finish | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.