Skip to content

Commit

Permalink
feat: custom retry strategy for broken Retry-After values
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Dec 23, 2023
1 parent e5e0961 commit ec6db75
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

public class JSkolengoAnonymous extends AbstractSkolengo {
public JSkolengoAnonymous() {
super(HttpClients.createDefault(), new ObjectMapper().registerModule(new JavaTimeModule()));
super(HttpClients.custom().setRetryStrategy(new SkolengoRetryStrategy()).build(),
new ObjectMapper().registerModule(new JavaTimeModule()));
}

public JSkolengoAnonymous(CloseableHttpClient client, ObjectMapper mapper, ResourceConverter converter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.vinceh121.jskolengo;

import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.TimeValue;

/**
* Certain endpoints like /evaluation-services return a 503 + Retry-After,
* triggering the retry strategy. However, the value in the header is
* erroneously specified in milliseconds instead of seconds
*/
public class SkolengoRetryStrategy extends DefaultHttpRequestRetryStrategy {
public SkolengoRetryStrategy() {
super(50, TimeValue.ofMilliseconds(500));
}

@Override
public TimeValue getRetryInterval(HttpResponse response, int execCount, HttpContext context) {
return super.getRetryInterval(response, execCount, context).divide(1000);
}
}

0 comments on commit ec6db75

Please sign in to comment.