Skip to content

Commit

Permalink
catch and handle max retries exception
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensel committed Oct 16, 2023
1 parent d71a2de commit fb352d7
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import clusterless.cls.json.JSONUtil;
import clusterless.cls.startup.Startup;
import io.github.resilience4j.core.IntervalFunction;
import io.github.resilience4j.core.StopWatch;
import io.github.resilience4j.retry.MaxRetriesExceededException;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -56,6 +58,7 @@ public int executeProcess(String... args) {
}

protected int executeProcess(Map<String, String> environment, List<String> args) {
StopWatch stopWatch = StopWatch.start();
try {
if (!retry()) {
// do not wrap the exec if retry is not enabled
Expand All @@ -77,6 +80,9 @@ protected int executeProcess(Map<String, String> environment, List<String> args)
Retry process = Retry.of("process", config);

return process.executeCheckedSupplier(() -> process(environment, args));
} catch (MaxRetriesExceededException e) {
LOG.error("failed to execute command: {} after {} retries, duration: {}", args, retries, stopWatch.stop(), e);
return 1;
} catch (Throwable e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit fb352d7

Please sign in to comment.