refactor(Worker): add retry logic on runProcessLoop. Throws exception after MAX_RETRIES

This commit is contained in:
glarwood 2018-12-11 19:46:40 -08:00
parent a116817710
commit 7417524649

View file

@ -66,6 +66,7 @@ public class Worker implements Runnable {
private static final Log LOG = LogFactory.getLog(Worker.class);
private static final int MAX_INITIALIZATION_ATTEMPTS = 20;
private static final int MAX_RETRIES = 4;
private WorkerLog wlog = new WorkerLog();
@ -370,6 +371,7 @@ public class Worker implements Runnable {
@VisibleForTesting
void runProcessLoop() {
for (int i = 0; ; i++) {
try {
boolean foundCompletedShard = false;
Set<ShardInfo> assignedShards = new HashSet<>();
@ -393,6 +395,8 @@ public class Worker implements Runnable {
wlog.info("Sleeping ...");
Thread.sleep(idleTimeInMilliseconds);
} catch (Exception e) {
if (i > MAX_RETRIES) throw new RuntimeException("Giving up after " + i + " retries", e);
LOG.error(String.format("Worker.run caught exception, sleeping for %s milli seconds!",
String.valueOf(idleTimeInMilliseconds)), e);
try {
@ -403,6 +407,7 @@ public class Worker implements Runnable {
}
wlog.resetInfoLogging();
}
}
private void initialize() {
boolean isDone = false;