Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Retry HTTP call on connection failure in sendHTTPReponse() + "Max retry" exception
.
. .
. . .
} 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
You can’t perform that action at this time.