1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

fixed proper stop and removal of subscriber procs

This commit is contained in:
postmannen 2022-06-23 11:40:17 +02:00
parent 11b0444929
commit 3458e655c0

View file

@ -227,6 +227,25 @@ func (p process) spawnWorker() {
} }
p.natsSubscription = p.subscribeMessages() p.natsSubscription = p.subscribeMessages()
// We also need to be able to remove all the information about this process
// when the process context is canceled.
go func() {
<-p.ctx.Done()
err := p.natsSubscription.Unsubscribe()
if err != nil {
er := fmt.Errorf("error: spawnWorker: got <-ctx.Done, but unable to unsubscribe natsSubscription failed: %v", err)
p.errorKernel.errSend(p, Message{}, er)
p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration)
}
p.processes.active.mu.Lock()
delete(p.processes.active.procNames, p.processName)
p.processes.active.mu.Unlock()
log.Printf("Successfully stopped process: %v\n", p.processName)
}()
} }
// Add information about the new process to the started processes map. // Add information about the new process to the started processes map.