mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 20:52:33 +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 {
|
func StartNotifDispatcher(parent *task.Task) *Dispatcher {
|
||||||
dispatcher = &Dispatcher{
|
dispatcher = &Dispatcher{
|
||||||
task: parent.Subtask("notification dispatcher"),
|
task: parent.Subtask("notification"),
|
||||||
logCh: make(chan *LogMessage),
|
logCh: make(chan *LogMessage),
|
||||||
providers: F.NewSet[Provider](),
|
providers: F.NewSet[Provider](),
|
||||||
}
|
}
|
||||||
|
@ -79,23 +79,27 @@ func (disp *Dispatcher) RegisterProvider(cfg types.NotificationConfig) (Provider
|
||||||
|
|
||||||
func (disp *Dispatcher) start() {
|
func (disp *Dispatcher) start() {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
dispatcher = nil
|
||||||
disp.providers.Clear()
|
disp.providers.Clear()
|
||||||
close(disp.logCh)
|
close(disp.logCh)
|
||||||
disp.task.Finish("dispatcher stopped")
|
disp.task.Finish(nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-disp.task.Context().Done():
|
case <-disp.task.Context().Done():
|
||||||
return
|
return
|
||||||
case msg := <-disp.logCh:
|
case msg, ok := <-disp.logCh:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
go disp.dispatch(msg)
|
go disp.dispatch(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (disp *Dispatcher) dispatch(msg *LogMessage) {
|
func (disp *Dispatcher) dispatch(msg *LogMessage) {
|
||||||
task := disp.task.Subtask("dispatch notif")
|
task := disp.task.Subtask("dispatcher")
|
||||||
defer task.Finish("notif dispatched")
|
defer task.Finish("notif dispatched")
|
||||||
|
|
||||||
errs := E.NewBuilder(dispatchErr)
|
errs := E.NewBuilder(dispatchErr)
|
||||||
|
|
Loading…
Add table
Reference in a new issue