private boolean waitForDeployment()

in src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java [454:506]


    private boolean waitForDeployment(AWSClients aws, String deploymentId) throws InterruptedException {

        if (!this.waitForCompletion) {
            return true;
        }

        logger.println("Monitoring deployment with ID " + deploymentId + "...");
        GetDeploymentRequest deployInfoRequest = new GetDeploymentRequest();
        deployInfoRequest.setDeploymentId(deploymentId);

        DeploymentInfo deployStatus = aws.codedeploy.getDeployment(deployInfoRequest).getDeploymentInfo();

        long startTimeMillis;
        if (deployStatus == null || deployStatus.getStartTime() == null) {
            startTimeMillis = new Date().getTime();
        } else {
            startTimeMillis = deployStatus.getStartTime().getTime();
        }

        boolean success = true;
        long pollingTimeoutMillis = this.pollingTimeoutSec * 1000L;
        long pollingFreqMillis = this.pollingFreqSec * 1000L;

        while (deployStatus == null || deployStatus.getCompleteTime() == null) {

            if (deployStatus == null) {
                logger.println("Deployment status: unknown.");
            } else {
                DeploymentOverview overview = deployStatus.getDeploymentOverview();
                logger.println("Deployment status: " + deployStatus.getStatus() + "; instances: " + overview);
            }

            deployStatus = aws.codedeploy.getDeployment(deployInfoRequest).getDeploymentInfo();
            Date now = new Date();

            if (now.getTime() - startTimeMillis >= pollingTimeoutMillis) {
                this.logger.println("Exceeded maximum polling time of " + pollingTimeoutMillis + " milliseconds.");
                success = false;
                break;
            }

            Thread.sleep(pollingFreqMillis);
        }

        logger.println("Deployment status: " + deployStatus.getStatus() + "; instances: " + deployStatus.getDeploymentOverview());

        if (!deployStatus.getStatus().equals(DeploymentStatus.Succeeded.toString())) {
            this.logger.println("Deployment did not succeed. Final status: " + deployStatus.getStatus());
            success = false;
        }

        return success;
    }