forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll_start.go
90 lines (80 loc) · 2.63 KB
/
poll_start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package shared
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/actor/v2action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/translatableerror"
)
func PollStart(ui command.UI, config command.Config, messages <-chan *v2action.LogMessage, logErrs <-chan error, appState <-chan v2action.ApplicationStateChange, apiWarnings <-chan string, apiErrs <-chan error) error {
var breakAppState, breakWarnings, breakAPIErrs bool
for {
select {
case message, ok := <-messages:
if !ok {
break
}
if message.Staging() {
ui.DisplayLogMessage(message, false)
}
case state, ok := <-appState:
if !ok {
breakAppState = true
break
}
switch state {
case v2action.ApplicationStateStopping:
ui.DisplayNewline()
ui.DisplayText("Stopping app...")
case v2action.ApplicationStateStaging:
ui.DisplayNewline()
ui.DisplayText("Staging app and tracing logs...")
case v2action.ApplicationStateStarting:
ui.DisplayNewline()
ui.DisplayText("Waiting for app to start...")
}
case warning, ok := <-apiWarnings:
if !ok {
breakWarnings = true
break
}
ui.DisplayWarning(warning)
case logErr, ok := <-logErrs:
if !ok {
break
}
switch logErr.(type) {
case actionerror.NOAATimeoutError:
ui.DisplayWarning("timeout connecting to log server, no log will be shown")
default:
ui.DisplayWarning(logErr.Error())
}
case apiErr, ok := <-apiErrs:
if !ok {
breakAPIErrs = true
break
}
switch err := apiErr.(type) {
case actionerror.StagingFailedError:
return translatableerror.StagingFailedError{Message: err.Error()}
case actionerror.StagingFailedNoAppDetectedError:
return translatableerror.StagingFailedNoAppDetectedError{BinaryName: config.BinaryName(), Message: err.Error()}
case actionerror.StagingTimeoutError:
return translatableerror.StagingTimeoutError{AppName: err.AppName, Timeout: err.Timeout}
case actionerror.ApplicationInstanceCrashedError:
return translatableerror.UnsuccessfulStartError{AppName: err.Name, BinaryName: config.BinaryName()}
case actionerror.ApplicationInstanceFlappingError:
return translatableerror.UnsuccessfulStartError{AppName: err.Name, BinaryName: config.BinaryName()}
case actionerror.StartupTimeoutError:
return translatableerror.StartupTimeoutError{AppName: err.Name, BinaryName: config.BinaryName()}
default:
return apiErr
}
}
// only wait for non-nil channels to be closed
if (appState == nil || breakAppState) &&
(apiWarnings == nil || breakWarnings) &&
(apiErrs == nil || breakAPIErrs) {
return nil
}
}
}