Change HTTP retry to 5 times every 20s and add HTTP exception logging
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/HttpClientWithRetry.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/HttpClientWithRetry.java
index 5e9ec56..f57a67b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/HttpClientWithRetry.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/HttpClientWithRetry.java
@@ -2,6 +2,7 @@
import com.github.rholder.retry.*;
import com.google.inject.Singleton;
+import lombok.extern.slf4j.Slf4j;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
@@ -13,6 +14,7 @@
import static java.net.HttpURLConnection.HTTP_OK;
@Singleton
+@Slf4j
public class HttpClientWithRetry {
private final Retryer<HttpResponse<String>> retryer;
@@ -21,11 +23,22 @@
.build();
public HttpClientWithRetry() {
+ //Attention, 'com.github.rholder.retry.RetryListener' is marked unstable with @Beta annotation
+ RetryListener listener = new RetryListener() {
+ @Override
+ public <V> void onRetry(Attempt<V> attempt) {
+ if (attempt.hasException()) {
+ log.error("Retry failed with exception: " + attempt.getExceptionCause());
+ }
+ }
+ };
+
this.retryer = RetryerBuilder.<HttpResponse<String>>newBuilder()
.retryIfException()
.retryIfResult(response -> response.statusCode() != HTTP_OK)
- .withWaitStrategy(WaitStrategies.fixedWait(10, TimeUnit.SECONDS))
- .withStopStrategy(StopStrategies.stopAfterAttempt(3))
+ .withWaitStrategy(WaitStrategies.fixedWait(20, TimeUnit.SECONDS))
+ .withStopStrategy(StopStrategies.stopAfterAttempt(5))
+ .withRetryListener(listener)
.build();
}