MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / WaitRun

Function WaitRun

pkg/cmd/task/wait/wait.go:101–210  ·  view source on GitHub ↗
(opts *WaitOptions)

Source from the content-addressed store, hash-verified

99}
100
101func WaitRun(opts *WaitOptions) error {
102 if len(opts.TaskIDs) == 0 {
103 return fmt.Errorf("no server task IDs provided, at least one is required")
104 }
105
106 if opts.ShowProgress && len(opts.TaskIDs) > 1 {
107 return fmt.Errorf("--progress flag is only supported when waiting for a single task")
108 }
109
110 serverTasks, err := opts.GetServerTasksCallback(opts.TaskIDs)
111 if err != nil {
112 return err
113 }
114
115 if len(serverTasks) == 0 {
116 return fmt.Errorf("no server tasks found")
117 }
118
119 pendingTaskIDs := make([]string, 0)
120 failedTaskIDs := make([]string, 0)
121 formatter := NewTaskOutputFormatter(opts.Out)
122 tableHeaderPrinted := false
123
124 for _, t := range serverTasks {
125 if t.IsCompleted == nil || !*t.IsCompleted {
126 pendingTaskIDs = append(pendingTaskIDs, t.ID)
127 }
128 if (t.IsCompleted != nil && *t.IsCompleted) && (t.FinishedSuccessfully != nil && !*t.FinishedSuccessfully) {
129 failedTaskIDs = append(failedTaskIDs, t.ID)
130 }
131
132 if shouldUseCustomOutputFormat(opts, t) {
133 printTaskWithCustomFormat(opts, t, &tableHeaderPrinted)
134 } else {
135 formatter.PrintTaskInfo(t)
136 }
137 }
138
139 if len(pendingTaskIDs) == 0 {
140 if len(failedTaskIDs) != 0 {
141 return fmt.Errorf("one or more deployment tasks failed: %s", strings.Join(failedTaskIDs, ", "))
142 }
143 return nil
144 }
145
146 gotError := make(chan error, 1)
147 done := make(chan bool, 1)
148 completedChildIds := make(map[string]bool)
149
150 go func() {
151 for len(pendingTaskIDs) != 0 {
152 time.Sleep(time.Duration(opts.PollInterval) * time.Second)
153 serverTasks, err = opts.GetServerTasksCallback(pendingTaskIDs)
154 if err != nil {
155 gotError <- err
156 return
157 }
158 for _, t := range serverTasks {

Callers 1

NewCmdWaitFunction · 0.85

Calls 6

PrintTaskInfoMethod · 0.95
PrintActivityElementMethod · 0.95
NewTaskOutputFormatterFunction · 0.85
removeTaskIDFunction · 0.85

Tested by

no test coverage detected