aboutsummaryrefslogtreecommitdiffstats
path: root/modules/queue
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-02-08 14:02:32 +0000
committerGitHub <noreply@github.com>2022-02-08 14:02:32 +0000
commitdf4401732825b9b378e51663d74edb795446f2d3 (patch)
tree645acf249857f7cc8d279d9ba1148c4b1a7efe62 /modules/queue
parent4d939845d20d377e06bce5b02667ff21f69c3beb (diff)
downloadgitea-df4401732825b9b378e51663d74edb795446f2d3.tar.gz
gitea-df4401732825b9b378e51663d74edb795446f2d3.zip
Restart zero worker if there is still work to do (#18658)
* 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. Also ensure that requested count is reset after pulls and push mirror sync requests and add some more trace logging to the queue push. Fix #18607 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/queue')
-rw-r--r--modules/queue/workerpool.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/queue/workerpool.go b/modules/queue/workerpool.go
index 20108d3588..39ea59b7b1 100644
--- a/modules/queue/workerpool.go
+++ b/modules/queue/workerpool.go
@@ -115,6 +115,9 @@ func (p *WorkerPool) hasNoWorkerScaling() bool {
return p.numberOfWorkers == 0 && (p.boostTimeout == 0 || p.boostWorkers == 0 || p.maxNumberOfWorkers == 0)
}
+// zeroBoost will add a temporary boost worker for a no worker queue
+// p.lock must be locked at the start of this function BUT it will be unlocked by the end of this function
+// (This is because addWorkers has to be called whilst unlocked)
func (p *WorkerPool) zeroBoost() {
ctx, cancel := context.WithTimeout(p.baseCtx, p.boostTimeout)
mq := GetManager().GetManagedQueue(p.qid)
@@ -316,6 +319,17 @@ func (p *WorkerPool) addWorkers(ctx context.Context, cancel context.CancelFunc,
}
p.pause()
}
+ select {
+ case <-p.baseCtx.Done():
+ // this worker queue is shut-down don't reboost
+ default:
+ if p.numberOfWorkers == 0 && atomic.LoadInt64(&p.numInQueue) > 0 {
+ // OK there are no workers but... there's still work to be done -> Reboost
+ p.zeroBoost()
+ // p.lock will be unlocked by zeroBoost
+ return
+ }
+ }
p.lock.Unlock()
}()
}