runservice executor: report running tasks

This commit is contained in:
Simone Gotti 2019-04-17 15:47:58 +02:00
parent adf9c73518
commit 455623e58a
2 changed files with 14 additions and 3 deletions

View File

@ -656,14 +656,17 @@ func (e *Executor) sendExecutorStatus(ctx context.Context) error {
labels = make(map[string]string) labels = make(map[string]string)
} }
activeTasks := e.runningTasks.len()
// Add special labels (and override config provided ones) // Add special labels (and override config provided ones)
arch := runtime.GOARCH arch := runtime.GOARCH
labels["arch"] = arch labels["arch"] = arch
executor := &types.Executor{ executor := &types.Executor{
ID: e.id, ID: e.id,
ListenURL: e.listenURL, ListenURL: e.listenURL,
Labels: labels, Labels: labels,
ActiveTasks: activeTasks,
} }
log.Debugf("send executor status: %s", util.Dump(executor)) log.Debugf("send executor status: %s", util.Dump(executor))
@ -1153,6 +1156,12 @@ func (r *runningTasks) delete(rtID string) {
delete(r.tasks, rtID) delete(r.tasks, rtID)
} }
func (r *runningTasks) len() int {
r.m.Lock()
defer r.m.Unlock()
return len(r.tasks)
}
func (e *Executor) handleTasks(ctx context.Context, c <-chan *types.ExecutorTask) { func (e *Executor) handleTasks(ctx context.Context, c <-chan *types.ExecutorTask) {
for et := range c { for et := range c {
go e.executeTask(ctx, et) go e.executeTask(ctx, et)

View File

@ -658,6 +658,8 @@ type Executor struct {
Labels map[string]string `json:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty"`
ActiveTasks int `json:"active_tasks,omitempty"`
// internal values not saved // internal values not saved
Revision int64 `json:"-"` Revision int64 `json:"-"`
} }