Skip to content

Commit

Permalink
⏳ Improve retryPolicy default and make it configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
psbrandt committed Mar 24, 2021
1 parent e5a9287 commit fe91b38
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>edu.phema</groupId>
<artifactId>phema-elm-to-ohdsi</artifactId>
<version>0.4.6-SNAPSHOT</version>
<version>0.4.6</version>
<packaging>jar</packaging>

<name>phema-elm-to-ohdsi</name>
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/edu/phema/elm_to_omop/api/CohortService.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,31 @@ public InclusionRuleReport getCohortDefinitionReport(Integer id) throws CohortSe
try {
omopService.queueCohortGeneration(id);

// Initialize retry settings
int maxRetries;
String maxRetriesProp = System.getProperty("edu.phema.maxRetries");

if (maxRetriesProp == null) {
maxRetries = 10;
} else {
maxRetries = Integer.parseInt(maxRetriesProp);
}

int maxDelay;
String maxDelayProp = System.getProperty("edu.phema.maxDelaySeconds");

if (maxRetriesProp == null) {
maxDelay = 90;
} else {
maxDelay = Integer.parseInt(maxDelayProp);
}

logger.info("Getting Cohort Report with maxRetries=" + maxRetries + " and maxDelay=" + maxDelay);

// Retry while the cohort is generating
RetryPolicy retryPolicy = new RetryPolicy();
retryPolicy.withMaxRetries(maxRetries);

retryPolicy.handleResultIf(info -> {
Optional<CohortGenerationInfo> maybeGenInfo = ((List<CohortGenerationInfo>) info).stream().filter(cgi -> cgi.getId().getCohortDefinitionId().equals(id)).findFirst();

Expand All @@ -293,7 +316,7 @@ public InclusionRuleReport getCohortDefinitionReport(Integer id) throws CohortSe

return genInfo.getStatus() != GenerationStatus.COMPLETE;
});
retryPolicy.withBackoff(1, 30, ChronoUnit.SECONDS);
retryPolicy.withBackoff(1, maxDelay, ChronoUnit.SECONDS);
Failsafe.with(retryPolicy).get(() -> omopService.getCohortDefinitionInfo(id));

// Retry until we actually get an inclusionRules result back
Expand Down

0 comments on commit fe91b38

Please sign in to comment.