fix: wait for final log flush before closing deploymentLogWriter (closes #4)
This commit is contained in:
parent
d4eae284b5
commit
69456abd25
@ -78,6 +78,7 @@ type deploymentLogWriter struct {
|
||||
lineBuffer bytes.Buffer // buffer for incomplete lines
|
||||
mu sync.Mutex
|
||||
done chan struct{}
|
||||
flushed sync.WaitGroup // waits for flush goroutine to finish
|
||||
flushCtx context.Context //nolint:containedctx // needed for async flush goroutine
|
||||
}
|
||||
|
||||
@ -87,6 +88,7 @@ func newDeploymentLogWriter(ctx context.Context, deployment *models.Deployment)
|
||||
done: make(chan struct{}),
|
||||
flushCtx: ctx,
|
||||
}
|
||||
w.flushed.Add(1)
|
||||
go w.runFlushLoop()
|
||||
|
||||
return w
|
||||
@ -128,12 +130,15 @@ func (w *deploymentLogWriter) Write(p []byte) (int, error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// Close stops the flush loop and performs a final flush.
|
||||
// Close stops the flush loop, waits for the final flush to complete.
|
||||
func (w *deploymentLogWriter) Close() {
|
||||
close(w.done)
|
||||
w.flushed.Wait()
|
||||
}
|
||||
|
||||
func (w *deploymentLogWriter) runFlushLoop() {
|
||||
defer w.flushed.Done()
|
||||
|
||||
ticker := time.NewTicker(logFlushInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user