refactor(notif): replace RangeAllParalel with for loop and WaitGroup in dispatch

This commit is contained in:
yusing
2025-08-16 23:58:59 +08:00
parent 6b89cd9106
commit a836920eca

View File

@@ -3,6 +3,7 @@ package notif
import (
"math"
"math/rand/v2"
"sync"
"time"
"github.com/rs/zerolog"
@@ -96,7 +97,11 @@ func (disp *Dispatcher) dispatch(msg *LogMessage) {
Str("level", msg.Level.String()).
Str("title", msg.Title).Logger()
disp.providers.RangeAllParallel(func(p Provider) {
var wg sync.WaitGroup
for p := range disp.providers.Range {
wg.Add(1)
go func(p Provider) {
defer wg.Done()
if err := msg.notify(task.Context(), p); err != nil {
msg := &RetryMessage{
Message: msg,
@@ -109,7 +114,9 @@ func (disp *Dispatcher) dispatch(msg *LogMessage) {
} else {
l.Debug().Str("provider", p.GetName()).Msg("notification sent successfully")
}
})
}(p)
}
wg.Wait()
}
func (disp *Dispatcher) processRetries() {