Skip to content

Commit b1dd300

Browse files
committed
Restart zero worker if there is still work to do
It is possible for the zero worker to timeout before all the work is finished. This may mean that work may take a long time to complete because a worker will only be induced on repushing. Fix #18607 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 3a91f84 commit b1dd300

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

modules/queue/workerpool.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ func (p *WorkerPool) hasNoWorkerScaling() bool {
115115
return p.numberOfWorkers == 0 && (p.boostTimeout == 0 || p.boostWorkers == 0 || p.maxNumberOfWorkers == 0)
116116
}
117117

118+
// zeroBoost will add a temporary boost worker for a no worker queue
119+
// p.lock must be locked at the start of this function BUT it will be unlocked by the end of this function
120+
// (This is because addWorkers has to be called whilst unlocked)
118121
func (p *WorkerPool) zeroBoost() {
119122
ctx, cancel := context.WithTimeout(p.baseCtx, p.boostTimeout)
120123
mq := GetManager().GetManagedQueue(p.qid)
@@ -316,6 +319,17 @@ func (p *WorkerPool) addWorkers(ctx context.Context, cancel context.CancelFunc,
316319
}
317320
p.pause()
318321
}
322+
select {
323+
case <-p.baseCtx.Done():
324+
// this worker queue is shut-down don't reboost
325+
default:
326+
if p.numberOfWorkers == 0 && atomic.LoadInt64(&p.numInQueue) > 0 {
327+
// OK there are no workers but... there's still work to be done -> Reboost
328+
p.zeroBoost()
329+
// p.lock will be unlocked by zeroBoost
330+
return
331+
}
332+
}
319333
p.lock.Unlock()
320334
}()
321335
}

0 commit comments

Comments
 (0)