Skip to content

Instantly share code, notes, and snippets.

@karanmalhi
Created May 21, 2012 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanmalhi/2765027 to your computer and use it in GitHub Desktop.
Save karanmalhi/2765027 to your computer and use it in GitHub Desktop.
deploymentStatus
private DeploymentStatus getDeploymentStatus(DeploymentAction latest) {
DeploymentStatus status;
if (Action.DELETE.equals(latest.getAction())) {
status = DeploymentStatus.DELETING;
} else {
boolean inProcess = false;
int failCount = 0;
// if size is 0, that means we do not have any status yes, a typical indication that the deployment on servers has not started yet.
if (latest.getStatuses().size() == 0) {
// the deployment is still in progress, i.e. about to start
status = DeploymentStatus.IN_PROGRESS;
return status;
}
for (ServerDeploy s : latest.getStatuses()) {
switch (s.getState()) {
case IN_PROCESS:
inProcess = true;
break;
case FAILED:
failCount++;
break;
}
}
// the order of check is critical here. Even if we get a failure, we still need to make sure that deployments on other servers complete
// i.e. you want to let the deployment finish on as many servers as possible , hence we want to keep it in progress till then
if (inProcess) {
status = DeploymentStatus.IN_PROGRESS;
} else if (failCount == 0) {
status = DeploymentStatus.SUCCESSFUL;
} else {
status = DeploymentStatus.FAILED;
}
}
return status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment