Skip to content
Snippets Groups Projects
Commit 2d38d1cb authored by Muskan Srivastava's avatar Muskan Srivastava
Browse files

changes made retry function

parent 954aa863
No related branches found
No related tags found
1 merge request!147Enabling retry for indexer to storage service calls
Pipeline #35310 passed
package org.opengroup.osdu.indexer.azure.service;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.github.resilience4j.core.IntervalFunction;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
......@@ -14,6 +17,7 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.List;
import java.util.function.Supplier;
import static io.github.resilience4j.retry.RetryConfig.custom;
......@@ -21,8 +25,6 @@ import static java.time.temporal.ChronoUnit.SECONDS;
public class RetryPolicy {
private static final int attempts =3;
private static final int waitDurationInMillis = 1000;
......@@ -36,15 +38,15 @@ public class RetryPolicy {
RetryConfig config = RetryConfig.<HttpResponse>custom()
.maxAttempts(attempts)
.waitDuration(Duration.ofMillis(waitDurationInMillis))
.retryOnResult(response -> response.getResponseCode() == 404)
.retryOnResult(response -> {
List<String> notFound = new Gson().fromJson(response.getBody(), List.class);
if(notFound.isEmpty()) {
return true;
}
return false;
})
.build();
return config;
// .retryOnResult(response -> response.getStatus() == 500)
// .retryOnException(e -> e instanceof WebServiceException)
// .retryExceptions(IOException.class, TimeoutException.class)
// .ignoreExceptions(BusinessException.class, OtherBusinessException.class)
// .failAfterMaxAttempts(true)
}
......
......@@ -4,6 +4,7 @@ package org.opengroup.osdu.indexer.azure.service;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import io.github.resilience4j.retry.RetryRegistry;
import lombok.var;
import org.opengroup.osdu.core.common.http.FetchServiceHttpRequest;
import org.opengroup.osdu.core.common.http.IUrlFetchService;
import org.opengroup.osdu.core.common.http.UrlFetchServiceImpl;
......@@ -28,10 +29,35 @@ public class UrlFetchServiceAzureImpl extends UrlFetchServiceImpl implements IUr
@Override
public HttpResponse sendRequest(FetchServiceHttpRequest httpRequest) throws URISyntaxException {
logger.info("inside azure impl muskan;");
HttpResponse output = this.retryFunction(httpRequest);
logger.info("response code" + output.getResponseCode());
HttpResponse output;
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
if(isGetStorageRecords(stackTraceElements))
{
logger.info("retry function");
output = this.retryFunction(httpRequest);
if(output!=null)
{
return output;
}
}
logger.info("no retry function");
output=super.sendRequest(httpRequest);
return output;
}
private boolean isGetStorageRecords(StackTraceElement[] stElements)
{
for (int i=1; i<stElements.length; i++)
{
if(stElements[i].getMethodName().equals("getRecords"))
{
return true;
}
}
return false;
}
public HttpResponse retryFunction(FetchServiceHttpRequest request)
{
......@@ -60,4 +86,5 @@ public class UrlFetchServiceAzureImpl extends UrlFetchServiceImpl implements IUr
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment