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

Function ServiceProgress

cli/command/service/progress/progress.go:74–214  ·  view source on GitHub ↗

ServiceProgress outputs progress information for convergence of a service. nolint:gocyclo

(ctx context.Context, apiClient client.APIClient, serviceID string, progressWriter io.WriteCloser)

Source from the content-addressed store, hash-verified

72//
73//nolint:gocyclo
74func ServiceProgress(ctx context.Context, apiClient client.APIClient, serviceID string, progressWriter io.WriteCloser) error {
75 defer progressWriter.Close()
76
77 progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false)
78
79 sigint := make(chan os.Signal, 1)
80 signal.Notify(sigint, os.Interrupt)
81 defer signal.Stop(sigint)
82
83 var (
84 updater progressUpdater
85 converged bool
86 convergedAt time.Time
87 monitor = 5 * time.Second
88 rollback bool
89 message *progress.Progress
90 )
91
92 for {
93 res, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{})
94 if err != nil {
95 return err
96 }
97
98 if res.Service.Spec.UpdateConfig != nil && res.Service.Spec.UpdateConfig.Monitor != 0 {
99 monitor = res.Service.Spec.UpdateConfig.Monitor
100 }
101
102 if updater == nil {
103 updater, err = initializeUpdater(res.Service, progressOut)
104 if err != nil {
105 return err
106 }
107 }
108
109 if res.Service.UpdateStatus != nil {
110 switch res.Service.UpdateStatus.State {
111 case swarm.UpdateStateUpdating:
112 rollback = false
113 case swarm.UpdateStateCompleted:
114 if !converged {
115 return nil
116 }
117 case swarm.UpdateStatePaused:
118 return fmt.Errorf("service update paused: %s", res.Service.UpdateStatus.Message)
119 case swarm.UpdateStateRollbackStarted:
120 if !rollback && res.Service.UpdateStatus.Message != "" {
121 progressOut.WriteProgress(progress.Progress{
122 ID: "rollback",
123 Action: res.Service.UpdateStatus.Message,
124 })
125 }
126 rollback = true
127 case swarm.UpdateStateRollbackPaused:
128 return fmt.Errorf("service rollback paused: %s", res.Service.UpdateStatus.Message)
129 case swarm.UpdateStateRollbackCompleted:
130 if !converged {
131 message = &progress.Progress{ID: "rollback", Message: res.Service.UpdateStatus.Message}

Callers

nothing calls this directly

Calls 7

initializeUpdaterFunction · 0.85
getActiveNodesFunction · 0.85
updateMethod · 0.65
CloseMethod · 0.45
ServiceInspectMethod · 0.45
WriteProgressMethod · 0.45
TaskListMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…