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

@ -50,7 +50,7 @@ func NewLevelQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue, error)
}
config := configInterface.(LevelQueueConfiguration)
queue, err := levelqueue.Open(config.DataDir)
internal, err := levelqueue.Open(config.DataDir)
if err != nil {
return nil, err
}
@ -58,7 +58,7 @@ func NewLevelQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue, error)
dataChan := make(chan Data, config.QueueLength)
ctx, cancel := context.WithCancel(context.Background())
return &LevelQueue{
queue := &LevelQueue{
pool: &WorkerPool{
baseCtx: ctx,
cancel: cancel,
@ -69,13 +69,15 @@ func NewLevelQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue, error)
boostTimeout: config.BoostTimeout,
boostWorkers: config.BoostWorkers,
},
queue: queue,
queue: internal,
exemplar: exemplar,
closed: make(chan struct{}),
terminated: make(chan struct{}),
workers: config.Workers,
name: config.Name,
}, nil
}
queue.pool.qid = GetManager().Add(queue, LevelQueueType, config, exemplar, queue.pool.AddWorkers, queue.pool.NumberOfWorkers)
return queue, nil
}
// Run starts to run the queue
@ -83,7 +85,9 @@ func (l *LevelQueue) Run(atShutdown, atTerminate func(context.Context, func()))
atShutdown(context.Background(), l.Shutdown)
atTerminate(context.Background(), l.Terminate)
go l.pool.addWorkers(l.pool.baseCtx, l.workers)
go func() {
_ = l.pool.AddWorkers(l.workers, 0)
}()
go l.readToChan()
@ -140,7 +144,7 @@ func (l *LevelQueue) readToChan() {
log.Trace("LevelQueue %s: task found: %#v", l.name, data)
l.pool.Push(data)
time.Sleep(time.Millisecond * 10)
time.Sleep(time.Millisecond * 100)
}
}
@ -183,6 +187,11 @@ func (l *LevelQueue) Terminate() {
}
}
// Name returns the name of this queue
func (l *LevelQueue) Name() string {
return l.name
}
func init() {
queuesMap[LevelQueueType] = NewLevelQueue
}