mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix notification dispatcher send on closed channel after disabling from config
This commit is contained in:
parent
751594860a
commit
1042d12df6
1 changed files with 8 additions and 4 deletions
|
@ -37,7 +37,7 @@ const dispatchErr = "notification dispatch error"
|
|||
|
||||
func StartNotifDispatcher(parent *task.Task) *Dispatcher {
|
||||
dispatcher = &Dispatcher{
|
||||
task: parent.Subtask("notification dispatcher"),
|
||||
task: parent.Subtask("notification"),
|
||||
logCh: make(chan *LogMessage),
|
||||
providers: F.NewSet[Provider](),
|
||||
}
|
||||
|
@ -79,23 +79,27 @@ func (disp *Dispatcher) RegisterProvider(cfg types.NotificationConfig) (Provider
|
|||
|
||||
func (disp *Dispatcher) start() {
|
||||
defer func() {
|
||||
dispatcher = nil
|
||||
disp.providers.Clear()
|
||||
close(disp.logCh)
|
||||
disp.task.Finish("dispatcher stopped")
|
||||
disp.task.Finish(nil)
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-disp.task.Context().Done():
|
||||
return
|
||||
case msg := <-disp.logCh:
|
||||
case msg, ok := <-disp.logCh:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
go disp.dispatch(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (disp *Dispatcher) dispatch(msg *LogMessage) {
|
||||
task := disp.task.Subtask("dispatch notif")
|
||||
task := disp.task.Subtask("dispatcher")
|
||||
defer task.Finish("notif dispatched")
|
||||
|
||||
errs := E.NewBuilder(dispatchErr)
|
||||
|
|
Loading…
Add table
Reference in a new issue