1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

queue: Send mails in parallel

This patch makes queue items deliver mail in parallel to all recipients.
This commit is contained in:
Alberto Bertogli
2015-11-13 01:35:13 +00:00
parent 77d547288f
commit 4de805ab34

View File

@@ -146,26 +146,36 @@ func (item *Item) SendLoop(q *Queue) {
var err error var err error
for time.Since(item.Created) < giveUpAfter { for time.Since(item.Created) < giveUpAfter {
// Send to all recipients that are still pending. // Send to all recipients that are still pending.
successful := 0 var wg sync.WaitGroup
for _, to := range item.To { for _, to := range item.To {
if err, ok := item.Results[to]; ok && err == nil { if err, ok := item.Results[to]; ok && err == nil {
// Successful send for this recipient, nothing to do. // Successful send for this recipient, nothing to do.
successful++
continue continue
} }
tr.LazyPrintf("%s sending", to) wg.Add(1)
go func(to string) {
defer wg.Done()
tr.LazyPrintf("%s sending", to)
// TODO: deliver, serially or in parallel with a waitgroup. err = q.courier.Deliver(item.From, to, item.Data)
err = q.courier.Deliver(item.From, to, item.Data) item.Results[to] = err
item.Results[to] = err
if err != nil { if err != nil {
tr.LazyPrintf("error: %v", err) tr.LazyPrintf("error: %v", err)
glog.Infof("%s -> %q fail: %v", item.ID, to, err) glog.Infof("%s -> %q fail: %v", item.ID, to, err)
} else { } else {
tr.LazyPrintf("%s successful", to)
glog.Infof("%s -> %q sent", item.ID, to)
}
}(to)
}
wg.Wait()
successful := 0
for _, to := range item.To {
if err, ok := item.Results[to]; ok && err == nil {
successful++ successful++
tr.LazyPrintf("%s successful", to)
glog.Infof("%s -> %q sent", item.ID, to)
} }
} }