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