-
-
Save morficus/5bd94e330bf4212679b5 to your computer and use it in GitHub Desktop.
Retry HTTP call on connection failure in sendHTTPReponse() + "Max retry" exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. . | |
. . . | |
} catch (IOException e) { | |
//If we have connectionRetryLimit set to > 0 then retry that many times. | |
if( numberOfAttempts <= retryLimit) { | |
listener.getLogger().println("Connection to remote server failed, waiting for to retry - " + this.pollInterval + " seconds until next attempt."); | |
// Sleep for 'pollInterval' seconds. | |
// Sleep takes miliseconds so need to convert this.pollInterval to milisecopnds (x 1000) | |
try { | |
// Could do with a better way of sleeping... | |
Thread.sleep(this.pollInterval * 1000); | |
} catch (InterruptedException ex) { | |
this.failBuild(ex, listener); | |
} | |
listener.getLogger().println("Retry attempt #" + numberOfAttempts + " out of " + retryLimit ); | |
numberOfAttempts++; | |
responseObject = sendHTTPCall(urlString, requestType, build, listener, numberOfAttempts); | |
}else if(numberOfAttempts > retryLimit){ | |
//reached the maximum number of retries, time to fail | |
this.failBuild(new Exception("Max number of connection retries have been exeeded."), listener); | |
}else{ | |
//something failed with the connection and we retried the max amount of times... so throw an exception to mark the build as failed. | |
this.failBuild(e, listener); | |
} | |
} finally { | |
. . . | |
. . | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment