Skip to content

Commit da695ed

Browse files
committed
Simplify Boost/Pause logic
go-gitea#18658 has added a check to see if we need to boost because there is still work to do however the check is slightly complex and not ideal. There's no point boosting if the queue is paused or can't scale. Therefore merge the two selects into one and add a check to p.paused. Signed-off-by: Andrew Thornton <[email protected]>
1 parent df44017 commit da695ed

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

modules/queue/workerpool.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,22 +308,18 @@ func (p *WorkerPool) addWorkers(ctx context.Context, cancel context.CancelFunc,
308308
p.cond.Broadcast()
309309
cancel()
310310
}
311-
if p.hasNoWorkerScaling() {
312-
select {
313-
case <-p.baseCtx.Done():
314-
// Don't warn if the baseCtx is shutdown
315-
default:
316-
log.Warn(
317-
"Queue: %d is configured to be non-scaling and has no workers - this configuration is likely incorrect.\n"+
318-
"The queue will be paused to prevent data-loss with the assumption that you will add workers and unpause as required.", p.qid)
319-
}
320-
p.pause()
321-
}
322311
select {
323312
case <-p.baseCtx.Done():
324-
// this worker queue is shut-down don't reboost
313+
// Don't warn or check for ongoing work if the baseCtx is shutdown
314+
case <-p.paused:
315+
// Don't warn or check for ongoing work if the pool is paused
325316
default:
326-
if p.numberOfWorkers == 0 && atomic.LoadInt64(&p.numInQueue) > 0 {
317+
if p.hasNoWorkerScaling() {
318+
log.Warn(
319+
"Queue: %d is configured to be non-scaling and has no workers - this configuration is likely incorrect.\n"+
320+
"The queue will be paused to prevent data-loss with the assumption that you will add workers and unpause as required.", p.qid)
321+
p.pause()
322+
} else if p.numberOfWorkers == 0 && atomic.LoadInt64(&p.numInQueue) > 0 {
327323
// OK there are no workers but... there's still work to be done -> Reboost
328324
p.zeroBoost()
329325
// p.lock will be unlocked by zeroBoost

0 commit comments

Comments
 (0)