Skip to content

Commit f2a9c37

Browse files
committed
In FlushAll, initiate FlushWithContext in parallel
For non-immediate queues, FlushWithContext takes at least 40ms to verify that all items are processed. Calling this in parallel allows for just a single 40ms delay, instead of 40ms per queue.
1 parent 187c349 commit f2a9c37

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

modules/queue/manager.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"code.gitea.io/gitea/modules/log"
1212
"code.gitea.io/gitea/modules/setting"
13+
14+
"golang.org/x/sync/errgroup"
1315
)
1416

1517
// Manager is a manager for the queues created by "CreateXxxQueue" functions, these queues are called "managed queues".
@@ -77,14 +79,14 @@ func (m *Manager) ManagedQueues() map[int64]ManagedWorkerPoolQueue {
7779
// FlushAll tries to make all managed queues process all items synchronously, until timeout or the queue is empty.
7880
// It is for testing purpose only. It's not designed to be used in a cluster.
7981
func (m *Manager) FlushAll(ctx context.Context, timeout time.Duration) error {
80-
var finalErr error
82+
g := errgroup.Group{}
8183
qs := m.ManagedQueues()
8284
for _, q := range qs {
83-
if err := q.FlushWithContext(ctx, timeout); err != nil {
84-
finalErr = err // TODO: in Go 1.20: errors.Join
85-
}
85+
g.Go(func() error {
86+
return q.FlushWithContext(ctx, timeout)
87+
})
8688
}
87-
return finalErr
89+
return g.Wait()
8890
}
8991

9092
// CreateSimpleQueue creates a simple queue from global setting config provider by name

0 commit comments

Comments
 (0)