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

Method update

cli/command/service/progress/progress.go:589–653  ·  view source on GitHub ↗

update writes out the progress of the replicated job.

(_ swarm.Service, tasks []swarm.Task, _ map[string]struct{}, _ bool)

Source from the content-addressed store, hash-verified

587
588// update writes out the progress of the replicated job.
589func (u *replicatedJobProgressUpdater) update(_ swarm.Service, tasks []swarm.Task, _ map[string]struct{}, _ bool) (bool, error) {
590 if !u.initialized {
591 u.writeOverallProgress(0, 0)
592
593 // only write out progress bars if there will be less than the maximum
594 if u.total <= maxProgressBars {
595 for i := 1; i <= u.total; i++ {
596 u.progressOut.WriteProgress(progress.Progress{
597 ID: fmt.Sprintf("%d/%d", i, u.total),
598 Action: " ",
599 })
600 }
601 }
602 u.initialized = true
603 }
604
605 // tasksBySlot is a mapping of slot number to the task valid for that slot.
606 // it deduplicated tasks occupying the same numerical slot but in different
607 // states.
608 tasksBySlot := make(map[int]swarm.Task)
609 for _, task := range tasks {
610 // first, check if the task belongs to this service iteration. skip
611 // tasks belonging to other iterations.
612 if task.JobIteration == nil || task.JobIteration.Index != u.jobIteration {
613 continue
614 }
615
616 // then, if the task is in an unknown state, ignore it.
617 if numberedStates[task.DesiredState] == 0 ||
618 numberedStates[task.Status.State] == 0 {
619 continue
620 }
621
622 // finally, check if the task already exists in the map
623 if existing, ok := tasksBySlot[task.Slot]; ok {
624 // if so, use the task with the lower actual state
625 if numberedStates[existing.Status.State] > numberedStates[task.Status.State] {
626 tasksBySlot[task.Slot] = task
627 }
628 } else {
629 // otherwise, just add it to the map.
630 tasksBySlot[task.Slot] = task
631 }
632 }
633
634 activeTasks := 0
635 completeTasks := 0
636
637 for i := 0; i < len(tasksBySlot); i++ {
638 task := tasksBySlot[i]
639 u.writeTaskProgress(task)
640
641 if numberedStates[task.Status.State] < numberedStates[swarm.TaskStateComplete] {
642 activeTasks++
643 }
644
645 if task.Status.State == swarm.TaskStateComplete {
646 completeTasks++

Callers

nothing calls this directly

Calls 3

writeOverallProgressMethod · 0.95
writeTaskProgressMethod · 0.95
WriteProgressMethod · 0.45

Tested by

no test coverage detected