()
| 66 | } |
| 67 | |
| 68 | func (m *ExecutionMonitor) Monitor() ExecutionStatus { |
| 69 | totalRetries := m.retries |
| 70 | for { |
| 71 | operation, err := m.mtaClient.GetMtaOperation(m.operationID, m.embed) |
| 72 | if err != nil { |
| 73 | ui.Failed("Could not get ongoing operation: %s", baseclient.NewClientError(err)) |
| 74 | return Failure |
| 75 | } |
| 76 | m.reportOperationMessages(operation) |
| 77 | switch operation.State { |
| 78 | case models.StateRUNNING: |
| 79 | time.Sleep(3 * time.Second) |
| 80 | case models.StateFINISHED: |
| 81 | ui.Say("Process finished.") |
| 82 | m.reportCommandForDownloadOfProcessLogs(m.operationID) |
| 83 | return Success |
| 84 | case models.StateABORTED: |
| 85 | ui.Say("Process was aborted.") |
| 86 | m.reportCommandForDownloadOfProcessLogs(m.operationID) |
| 87 | return Failure |
| 88 | case models.StateERROR: |
| 89 | if canRetry(m.retries, operation) { |
| 90 | ui.Say("Proceeding with automatic retry... (%d of %d attempts left)", m.retries, totalRetries) |
| 91 | executeRetryAction(m) |
| 92 | continue |
| 93 | } |
| 94 | messageInError := findErrorMessage(operation.Messages) |
| 95 | if messageInError == nil { |
| 96 | ui.Failed("There is no error message for operation with ID %s", m.operationID) |
| 97 | return Failure |
| 98 | } |
| 99 | ui.Say("Process failed.") |
| 100 | m.reportAvaiableActions(m.operationID) |
| 101 | m.reportCommandForDownloadOfProcessLogs(m.operationID) |
| 102 | return Failure |
| 103 | case models.StateACTIONREQUIRED: |
| 104 | intermediatePhase, flag := getIntermediatePhaseAndFlag(m.commandName) |
| 105 | ui.Say("Process has entered %s phase. After testing your new deployment you can resume or abort the process.", intermediatePhase) |
| 106 | m.reportAvaiableActions(m.operationID) |
| 107 | ui.Say("Hint: Use the %q option of the %s command to skip this phase.", flag, m.commandName) |
| 108 | return Success |
| 109 | default: |
| 110 | ui.Failed("Process is in illegal state %s.", terminal.EntityNameColor(string(operation.State))) |
| 111 | return Failure |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | func getIntermediatePhaseAndFlag(commandName string) (string, string) { |
| 117 | //for backwards compatibility until the bg-deploy deprecation period expires |
no test coverage detected