Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only attempt to flush queue if the underlying worker pool is not finished #18593

Merged
merged 4 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/queue/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type ManagedPool interface {
BoostWorkers() int
// SetPoolSettings sets the user updatable settings for the pool
SetPoolSettings(maxNumberOfWorkers, boostWorkers int, timeout time.Duration)
// Done returns a channel that will be closed when this Pool's baseCtx is closed
zeripath marked this conversation as resolved.
Show resolved Hide resolved
Done() <-chan struct{}
}

// ManagedQueueList implements the sort.Interface
Expand Down Expand Up @@ -211,6 +213,15 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
continue
}
}
if pool, ok := mq.Managed.(ManagedPool); ok {
// no point flushing pools were their base ctx is already done
zeripath marked this conversation as resolved.
Show resolved Hide resolved
select {
case <-pool.Done():
wg.Done()
continue
default:
}
}

allEmpty = false
if flushable, ok := mq.Managed.(Flushable); ok {
Expand Down
5 changes: 5 additions & 0 deletions modules/queue/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func NewWorkerPool(handle HandlerFunc, config WorkerPoolConfiguration) *WorkerPo
return pool
}

// Done returns when this worker pool's base context has been cancelled
func (p *WorkerPool) Done() <-chan struct{} {
return p.baseCtx.Done()
}

// Push pushes the data to the internal channel
func (p *WorkerPool) Push(data Data) {
atomic.AddInt64(&p.numInQueue, 1)
Expand Down