private void waitForSuccessResult()

in command.line/java/com/jetbrains/teamcity/command/RemoteRun.java [365:419]


  private void waitForSuccessResult(final long changeListId, final long timeOut, IProgressMonitor monitor) throws ERemoteError {
    sleep(3000);
    monitor.beginTask("Waiting for Remote Run to finish");
    final long startTime = System.currentTimeMillis();
    UserChangeStatus prevCurrentStatus = null;
    while ((System.currentTimeMillis() - startTime) < timeOut) {

      final List<UserChangeInfoData> personalChanges = getPersonalChanges();
      if (personalChanges == null) {
        if (processFailureAndContinue()) {
          continue;
        }
        else {
          throw new RuntimeException("Error obtaining remote run status after multiple attempts", myRecentSummaryError);
        }
      }
      mySummaryFailureCount = 0;

      for (final UserChangeInfoData data : personalChanges) {

        if (data.getPersonalDesc() != null && data.getPersonalDesc().getId() == changeListId) {
          // check builds status
          final UserChangeStatus currentStatus = data.getChangeStatus();
          if (!currentStatus.equals(prevCurrentStatus)) {
            prevCurrentStatus = currentStatus;

            System.out.print(getBuildStatusDescription(currentStatus));
          }

          if (UserChangeStatus.FAILED_WITH_RESPONSIBLE == currentStatus || UserChangeStatus.FAILED == currentStatus || UserChangeStatus.CANCELED == currentStatus) {
            System.out.println();
            throw new ERemoteError("Remote Run failed: build status=" + getBuildStatusDescription(currentStatus));
          }

          if (UserChangeStatus.RUNNING_FAILED == currentStatus) {
            System.out.println("Remote Run failed: build status=" + getBuildStatusDescription(currentStatus));
          }

          if (UserChangeStatus.CHECKED == currentStatus) {
            // Successful finish
            System.out.println();
            // OK
            monitor.done();
            return;
          }

        }

      }
      System.out.print(".");
      ThreadUtil.sleep(SLEEP_INTERVAL);
    }
    // so, timeout exceed
    throw new RuntimeException(String.format("Stopped waiting for Remote Run %s, timeout exceeded: %dms", myTimeout, changeListId));
  }