1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add more details to RunningTasksCount

Provide slightly better information about the current state
of tasks.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-02-27 17:08:44 +01:00
parent de7172b600
commit 67d6f174ae
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -55,18 +55,30 @@ func RunningTasksCount(client client.ServiceAPIClient, serviceID string, instanc
tasks, err := client.TaskList(context.Background(), types.TaskListOptions{
Filters: filter,
})
var running int
var taskError string
for _, task := range tasks {
switch task.Status.State {
case swarmtypes.TaskStateRunning:
running++
case swarmtypes.TaskStateFailed:
if task.Status.Err != "" {
taskError = task.Status.Err
}
}
}
switch {
case err != nil:
return poll.Error(err)
case len(tasks) == int(instances):
for _, task := range tasks {
if task.Status.State != swarmtypes.TaskStateRunning {
return poll.Continue("waiting for tasks to enter run state")
}
}
case running > int(instances):
return poll.Continue("waiting for tasks to terminate")
case running < int(instances) && taskError != "":
return poll.Continue("waiting for tasks to enter run state. task failed with error: %s", taskError)
case running == int(instances):
return poll.Success()
default:
return poll.Continue("task count at %d waiting for %d", len(tasks), instances)
return poll.Continue("running task count at %d waiting for %d (total tasks: %d)", running, instances, len(tasks))
}
}
}