MCPcopy Index your code
hub / github.com/docker/cli / update

Method update

cli/command/service/progress/progress.go:416–472  ·  view source on GitHub ↗
(_ swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool)

Source from the content-addressed store, hash-verified

414}
415
416func (u *globalProgressUpdater) update(_ swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool) (bool, error) {
417 tasksByNode := u.tasksByNode(tasks)
418
419 // We don't have perfect knowledge of how many nodes meet the
420 // constraints for this service. But the orchestrator creates tasks
421 // for all eligible nodes at the same time, so we should see all those
422 // nodes represented among the up-to-date tasks.
423 nodeCount := len(tasksByNode)
424
425 if !u.initialized {
426 if nodeCount == 0 {
427 // Two possibilities: either the orchestrator hasn't created
428 // the tasks yet, or the service doesn't meet constraints for
429 // any node. Either way, we wait.
430 u.progressOut.WriteProgress(progress.Progress{
431 ID: "overall progress",
432 Action: "waiting for new tasks",
433 })
434 return false, nil
435 }
436
437 writeOverallProgress(u.progressOut, 0, nodeCount, rollback)
438 u.initialized = true
439 }
440
441 // If we had reached a converged state, check if we are still converged.
442 if u.done {
443 for _, task := range tasksByNode {
444 if task.Status.State != swarm.TaskStateRunning {
445 u.done = false
446 break
447 }
448 }
449 }
450
451 running := 0
452
453 for _, task := range tasksByNode {
454 if _, nodeActive := activeNodes[task.NodeID]; nodeActive {
455 if !terminalState(task.DesiredState) && task.Status.State == swarm.TaskStateRunning {
456 running++
457 }
458
459 u.writeTaskProgress(task, nodeCount)
460 }
461 }
462
463 if !u.done {
464 writeOverallProgress(u.progressOut, running, nodeCount, rollback)
465
466 if running == nodeCount {
467 u.done = true
468 }
469 }
470
471 return running == nodeCount, nil
472}
473

Callers

nothing calls this directly

Calls 5

tasksByNodeMethod · 0.95
writeTaskProgressMethod · 0.95
writeOverallProgressFunction · 0.85
terminalStateFunction · 0.70
WriteProgressMethod · 0.45

Tested by

no test coverage detected