Skip to content

Commit

Permalink
Nicer logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorper committed Feb 1, 2025
1 parent 68710d1 commit 09fc121
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;

import java.time.Duration;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
Expand All @@ -21,7 +22,8 @@ public class RetryUtils {

public static WaitStrategy defaultWaitStrategy() {
return WaitStrategies.join(
WaitStrategies.exponentialWait(1_000,30_000, TimeUnit.MILLISECONDS)
WaitStrategies.randomWait(200,TimeUnit.MILLISECONDS),
WaitStrategies.exponentialWait(1_000,10_000, TimeUnit.MILLISECONDS)
);
}

Expand All @@ -31,9 +33,9 @@ public static RetryListener logRetry(final Logger log, String className) {
public <V> void onRetry(Attempt<V> attempt) {
if (attempt.getAttemptNumber() > 1 || attempt.hasException()) {
if (attempt.hasException()) {
log.log(Level.WARNING, "%s, Retry attempt: %d, wait: %d".formatted(className, attempt.getAttemptNumber(), attempt.getDelaySinceFirstAttempt()), attempt.getExceptionCause());
log.log(Level.WARNING, "%s, Attempt #%d. Retrying...".formatted(className, attempt.getAttemptNumber()), attempt.getExceptionCause());
} else {
log.log(Level.WARNING, "%s, Retry attempt: %d, wait: %d. No exception?".formatted(className, attempt.getAttemptNumber(), attempt.getDelaySinceFirstAttempt()));
log.log(Level.WARNING, "%s, Attempt #%d OK, wait: %s".formatted(className, attempt.getAttemptNumber(), Duration.ofMillis(attempt.getDelaySinceFirstAttempt())));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import lombok.extern.java.Log;

import java.io.IOException;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -97,9 +98,9 @@ public <V> void onRetry(Attempt<V> attempt) {
if (attempt.getAttemptNumber() > 1 || attempt.hasException()) {
String className = AppEngineBackEnd.class.getName();
if (attempt.hasException()) {
log.log(Level.WARNING, "%s, Retry attempt: %d, wait: %d".formatted(className, attempt.getAttemptNumber(), attempt.getDelaySinceFirstAttempt()), attempt.getExceptionCause());
log.log(Level.WARNING, "%s, Attempt #%d. Retrying...".formatted(className, attempt.getAttemptNumber()), attempt.getExceptionCause());
} else {
log.log(Level.WARNING, "%s, Retry attempt: %d, wait: %d. No exception?".formatted(className, attempt.getAttemptNumber(), attempt.getDelaySinceFirstAttempt()));
log.log(Level.WARNING, "%s, Attempt #%d OK, wait: %s".formatted(className, attempt.getAttemptNumber(), Duration.ofMillis(attempt.getDelaySinceFirstAttempt())));
}
}
}
Expand Down

0 comments on commit 09fc121

Please sign in to comment.