Worker: sign off as last step of shutdown

Within the shutdown procedure, signing off is now the last thing the
worker does. This makes things more consistent from the Manager's point
of view (like receiving last-second log entries while the Worker is still
online).
This commit is contained in:
Sybren A. Stüvel 2022-06-16 12:19:03 +02:00
parent 5bc94101e8
commit 9ddf72fa37
2 changed files with 5 additions and 4 deletions

View File

@ -144,14 +144,16 @@ func shutdown() {
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
if w != nil { if w != nil {
shutdownCtx, cancelFunc := context.WithTimeout(context.Background(), 3*time.Second)
defer cancelFunc()
w.SignOff(shutdownCtx)
w.Close() w.Close()
listener.Wait() listener.Wait()
if err := buffer.Close(); err != nil { if err := buffer.Close(); err != nil {
log.Error().Err(err).Msg("closing upstream task buffer") log.Error().Err(err).Msg("closing upstream task buffer")
} }
// Sign off as the last step. Any flushes should happen while we're still signed on.
signoffCtx, cancelFunc := context.WithTimeout(context.Background(), 3*time.Second)
defer cancelFunc()
w.SignOff(signoffCtx)
} }
close(done) close(done)
}() }()

View File

@ -63,5 +63,4 @@ func (w *Worker) Close() {
log.Debug().Msg("worker gracefully shutting down") log.Debug().Msg("worker gracefully shutting down")
close(w.doneChan) close(w.doneChan)
w.doneWg.Wait() w.doneWg.Wait()
log.Debug().Msg("worker shut down")
} }