Skip to content

Commit 5748ea4

Browse files
author
Hemed Ali
committed
Add limit to the retry attempt
1 parent aa524f9 commit 5748ea4

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.elasticsearch.plugin.river.ubb</groupId>
55
<artifactId>ubb-rdf-river-plugin</artifactId>
6-
<version>1.7.6</version>
6+
<version>1.7.7</version>
77

88
<packaging>jar</packaging>
99

src/main/java/org/elasticsearch/river/ubb/support/Harvester.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.elasticsearch.river.ubb.support;
22

3+
import org.apache.jena.atlas.web.HttpException;
34
import org.apache.jena.graph.Graph;
45
import org.apache.jena.graph.Node;
56
import org.apache.jena.graph.NodeFactory;
@@ -1053,22 +1054,31 @@ private Model getModel(QueryExecution qexec) {
10531054
*/
10541055
private void harvest(QueryExecution qexec) throws IOException {
10551056
boolean retry;
1057+
int countRetry = 0;
1058+
int totalRetry = 5;
10561059
do {
10571060
retry = false;
10581061
try {
10591062
Model model = getModel(qexec);
10601063
addModelToElasticsearch(model, client.prepareBulk());
1061-
} catch (QueryExceptionHTTP httpe) {
1064+
}
1065+
catch (QueryExceptionHTTP httpe) {
10621066
if (httpe.getResponseCode() >= 500) {
10631067
retry = true;
1064-
logger.error("Encountered an internal server error "
1065-
+ "while harvesting. Retrying!");
1068+
countRetry++;
1069+
logger.error("Encountered internal server error while harvesting. " +
1070+
"Retrying... {}", countRetry);
10661071
} else {
10671072
throw httpe;
10681073
}
1069-
} catch (Exception e) {
1070-
logger.error("Exception occurred while harvesting " +
1071-
"with details: [{}] ", e.getLocalizedMessage());
1074+
if (countRetry > totalRetry) {
1075+
//if we have reached maximum retries, exit
1076+
break;
1077+
}
1078+
}
1079+
catch (Exception e) {
1080+
logger.error("Exception occurred while harvesting with details: [{}] ",
1081+
e.getLocalizedMessage());
10721082
e.printStackTrace();
10731083
}
10741084
} while (retry);

0 commit comments

Comments
 (0)