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 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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue