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

Method update

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

Source from the content-addressed store, hash-verified

292}
293
294func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm.Task, activeNodes map[string]struct{}, rollback bool) (bool, error) {
295 if service.Spec.Mode.Replicated == nil || service.Spec.Mode.Replicated.Replicas == nil {
296 return false, errors.New("no replica count")
297 }
298 replicas := *service.Spec.Mode.Replicated.Replicas
299
300 if !u.initialized {
301 u.slotMap = make(map[int]int)
302
303 // Draw progress bars in order
304 writeOverallProgress(u.progressOut, 0, int(replicas), rollback)
305
306 if replicas <= maxProgressBars {
307 for i := uint64(1); i <= replicas; i++ {
308 progress.Update(u.progressOut, fmt.Sprintf("%d/%d", i, replicas), " ")
309 }
310 }
311 u.initialized = true
312 }
313
314 tasksBySlot := u.tasksBySlot(tasks, activeNodes)
315
316 // If we had reached a converged state, check if we are still converged.
317 if u.done {
318 for _, task := range tasksBySlot {
319 if task.Status.State != swarm.TaskStateRunning {
320 u.done = false
321 break
322 }
323 }
324 }
325
326 running := uint64(0)
327
328 for _, task := range tasksBySlot {
329 mappedSlot := u.slotMap[task.Slot]
330 if mappedSlot == 0 {
331 mappedSlot = len(u.slotMap) + 1
332 u.slotMap[task.Slot] = mappedSlot
333 }
334
335 if !terminalState(task.DesiredState) && task.Status.State == swarm.TaskStateRunning {
336 running++
337 }
338
339 u.writeTaskProgress(task, mappedSlot, replicas)
340 }
341
342 if !u.done {
343 writeOverallProgress(u.progressOut, int(running), int(replicas), rollback)
344
345 if running == replicas {
346 u.done = true
347 }
348 }
349
350 return running == replicas, nil
351}

Callers

nothing calls this directly

Calls 4

tasksBySlotMethod · 0.95
writeTaskProgressMethod · 0.95
writeOverallProgressFunction · 0.85
terminalStateFunction · 0.70

Tested by

no test coverage detected