Skip to content

Commit

Permalink
Merge pull request #240 from intuit/feature/failsafe-retry
Browse files Browse the repository at this point in the history
Feature/failsafe retry : Exponential backoff based retry mechanism for assignment export
  • Loading branch information
abhishekjain88 committed May 12, 2017
2 parents 8d27e62 + b909e8f commit 7c59a33
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/export/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>failsafe</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*******************************************************************************/
package com.intuit.wasabi.export.rest;

import net.jodah.failsafe.RetryPolicy;

import java.net.URI;

/**
Expand All @@ -40,6 +42,12 @@ public interface RestEndPoint {
*/
int getRetries();

/**
* Retry policy
* @return retry policy
*/
RetryPolicy getRetryPolicy();

/**
* Configuration parames for rest endpoint
*/
Expand Down Expand Up @@ -80,5 +88,20 @@ interface Configuration {
* @return retries
*/
int getRetries();

/**
* Is exponential backoff enabled
*/
boolean isExponentialBackoffEnabled();

/**
* Get exponential backoff initial delay
*/
long getExponentialBackoffDelay();

/**
* Get exponential backoff max delay
*/
long getExponentialBackoffMaxDelay();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

import com.google.inject.Inject;
import com.intuit.wasabi.export.rest.RestEndPoint;
import net.jodah.failsafe.RetryPolicy;
import org.apache.http.client.utils.URIBuilder;
import org.slf4j.Logger;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;

import static org.slf4j.LoggerFactory.getLogger;

Expand Down Expand Up @@ -62,4 +64,14 @@ public Boolean useProxy() {
public int getRetries() {
return configuration.getRetries();
}

@Override
public RetryPolicy getRetryPolicy() {
RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(configuration.getRetries());
if (configuration.isExponentialBackoffEnabled()) {
retryPolicy = retryPolicy.withBackoff(configuration.getExponentialBackoffDelay(),
configuration.getExponentialBackoffMaxDelay(), TimeUnit.SECONDS);
}
return retryPolicy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,34 @@ public Boolean useProxy() {
public int getRetries() {
return Integer.parseInt((String) properties.get("export.rest.retries"));
}

/**
* Returns the export rest endpoint is exponential backoff enabled property.
*
* @return whether exponential backoff is enabled for retries
*/
@Override
public boolean isExponentialBackoffEnabled() {
return Boolean.parseBoolean(properties.getProperty("export.rest.isExponentialBackoffEnabled"));
}

/**
* Returns the export rest endpoint exponential backoff initial delay
*
* @return initial interval size between retries with exponential backoff enabled
*/
@Override
public long getExponentialBackoffDelay() {
return Long.parseLong(properties.getProperty("export.rest.exponentialBackoffDelay"));
}

/**
* Returns the export rest endpoint exponential backoff max delay
*
* @return the maximum interval size until which retries are going to continue with exponential backoff strategy
*/
@Override
public long getExponentialBackoffMaxDelay() {
return Long.parseLong(properties.getProperty("export.rest.exponentialBackoffMaxDelay"));
}
}
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ http://www.w3.org/2001/XMLSchema-instance">
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>failsafe</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
Expand Down

0 comments on commit 7c59a33

Please sign in to comment.