Skip to content

Commit

Permalink
Remove retries from Java
Browse files Browse the repository at this point in the history
Increased the scope of retries in the previous commit.
  • Loading branch information
hubertp committed Oct 8, 2024
1 parent 6638f0a commit b1de982
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type HTTP
all_headers = headers + boundary_header_list
mapped_headers = all_headers.map on_problems=No_Wrap .to_java_pair

response = Response.Value (EnsoSecretHelper.makeRequest self.internal_http_client builder req.uri.to_java_representation mapped_headers (req.method == HTTP_Method.Get))
response = Response.Value (EnsoSecretHelper.makeRequest self.internal_http_client builder req.uri.to_java_representation mapped_headers)
if error_on_failure_code.not || response.code.is_success then response else
body = response.body.decode_as_text.catch Any _->""
message = if body.is_empty then Nothing else body
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.enso.base.enso_cloud;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
Expand All @@ -19,8 +18,6 @@
/** Makes HTTP requests with secrets in either header or query string. */
public final class EnsoSecretHelper extends SecretValueResolver {

private static final int MAX_RETRY_ATTEMPTS = 3;

/** Gets a JDBC connection resolving EnsoKeyValuePair into the properties. */
public static Connection getJDBCConnection(
String url, List<Pair<String, HideableValue>> properties) throws SQLException {
Expand Down Expand Up @@ -61,8 +58,7 @@ public static EnsoHttpResponse makeRequest(
HttpClient client,
Builder builder,
URIWithSecrets uri,
List<Pair<String, HideableValue>> headers,
Boolean withRetries)
List<Pair<String, HideableValue>> headers)
throws IllegalArgumentException, IOException, InterruptedException {

// Build a new URI with the query arguments.
Expand Down Expand Up @@ -92,30 +88,8 @@ public static EnsoHttpResponse makeRequest(
// Build and Send the request.
var httpRequest = builder.build();
var bodyHandler = HttpResponse.BodyHandlers.ofInputStream();
var javaResponse = client.send(httpRequest, bodyHandler);

HttpResponse<InputStream> javaResponse = null;
var attempts = 0;
IOException failure = null;
while (attempts < MAX_RETRY_ATTEMPTS && javaResponse == null) {
try {
javaResponse = client.send(httpRequest, bodyHandler);
} catch (IOException ioe) {
if (withRetries) {
if (failure == null) {
failure = ioe;
}
attempts += 1;
Thread.sleep(Double.valueOf(Math.min(100 * Math.pow(2, attempts - 1), 5000)).longValue());
} else {
throw ioe;
}
}
}
if (attempts == MAX_RETRY_ATTEMPTS) {
throw failure;
}

assert javaResponse != null;
// Extract parts of the response
return new EnsoHttpResponse(
renderedURI, javaResponse.headers(), javaResponse.body(), javaResponse.statusCode());
Expand Down

0 comments on commit b1de982

Please sign in to comment.