refactor(Worker): add retry logic on runProcessLoop. Throws exception after MAX_RETRIES
This commit is contained in:
parent
a116817710
commit
7417524649
1 changed files with 33 additions and 28 deletions
|
|
@ -66,6 +66,7 @@ public class Worker implements Runnable {
|
||||||
private static final Log LOG = LogFactory.getLog(Worker.class);
|
private static final Log LOG = LogFactory.getLog(Worker.class);
|
||||||
|
|
||||||
private static final int MAX_INITIALIZATION_ATTEMPTS = 20;
|
private static final int MAX_INITIALIZATION_ATTEMPTS = 20;
|
||||||
|
private static final int MAX_RETRIES = 4;
|
||||||
|
|
||||||
private WorkerLog wlog = new WorkerLog();
|
private WorkerLog wlog = new WorkerLog();
|
||||||
|
|
||||||
|
|
@ -370,6 +371,7 @@ public class Worker implements Runnable {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void runProcessLoop() {
|
void runProcessLoop() {
|
||||||
|
for (int i = 0; ; i++) {
|
||||||
try {
|
try {
|
||||||
boolean foundCompletedShard = false;
|
boolean foundCompletedShard = false;
|
||||||
Set<ShardInfo> assignedShards = new HashSet<>();
|
Set<ShardInfo> assignedShards = new HashSet<>();
|
||||||
|
|
@ -393,6 +395,8 @@ public class Worker implements Runnable {
|
||||||
wlog.info("Sleeping ...");
|
wlog.info("Sleeping ...");
|
||||||
Thread.sleep(idleTimeInMilliseconds);
|
Thread.sleep(idleTimeInMilliseconds);
|
||||||
} catch (Exception e) {
|
} 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!",
|
LOG.error(String.format("Worker.run caught exception, sleeping for %s milli seconds!",
|
||||||
String.valueOf(idleTimeInMilliseconds)), e);
|
String.valueOf(idleTimeInMilliseconds)), e);
|
||||||
try {
|
try {
|
||||||
|
|
@ -403,6 +407,7 @@ public class Worker implements Runnable {
|
||||||
}
|
}
|
||||||
wlog.resetInfoLogging();
|
wlog.resetInfoLogging();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
boolean isDone = false;
|
boolean isDone = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue