1
0
Fork 0
forked from forgejo/forgejo

Queue: Add monitoring

This commit is contained in:
Andrew Thornton 2019-12-07 16:48:21 +00:00
parent 85d1a7f7d2
commit 2927bc6fe5
No known key found for this signature in database
GPG key ID: 3CDE74631F13A748
13 changed files with 541 additions and 20 deletions

View file

@ -18,6 +18,7 @@ type WorkerPool struct {
baseCtx context.Context
cancel context.CancelFunc
cond *sync.Cond
qid int64
numberOfWorkers int
batchLength int
handle HandlerFunc
@ -68,8 +69,21 @@ func (p *WorkerPool) pushBoost(data Data) {
return
}
p.blockTimeout *= 2
log.Warn("Worker Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", ourTimeout, p.boostWorkers, p.boostTimeout, p.blockTimeout)
ctx, cancel := context.WithCancel(p.baseCtx)
desc := GetManager().GetDescription(p.qid)
if desc != nil {
log.Warn("Worker Channel for %v blocked for %v - adding %d temporary workers for %s, block timeout now %v", desc.Name, ourTimeout, p.boostWorkers, p.boostTimeout, p.blockTimeout)
start := time.Now()
pid := desc.RegisterWorkers(p.boostWorkers, start, false, start, cancel)
go func() {
<-ctx.Done()
desc.RemoveWorkers(pid)
cancel()
}()
} else {
log.Warn("Worker Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", ourTimeout, p.boostWorkers, p.boostTimeout, p.blockTimeout)
}
go func() {
<-time.After(p.boostTimeout)
cancel()
@ -95,12 +109,26 @@ func (p *WorkerPool) NumberOfWorkers() int {
func (p *WorkerPool) AddWorkers(number int, timeout time.Duration) context.CancelFunc {
var ctx context.Context
var cancel context.CancelFunc
start := time.Now()
end := start
hasTimeout := false
if timeout > 0 {
ctx, cancel = context.WithTimeout(p.baseCtx, timeout)
end = start.Add(timeout)
hasTimeout = true
} else {
ctx, cancel = context.WithCancel(p.baseCtx)
}
desc := GetManager().GetDescription(p.qid)
if desc != nil {
pid := desc.RegisterWorkers(number, start, hasTimeout, end, cancel)
go func() {
<-ctx.Done()
desc.RemoveWorkers(pid)
cancel()
}()
}
p.addWorkers(ctx, number)
return cancel
}