Skip to content

Commit b397d21

Browse files
committed
refactor: remove dup'd code
1 parent cd9abc2 commit b397d21

1 file changed

Lines changed: 1 addition & 22 deletions

File tree

src/main/java/dev/openfga/sdk/util/ExponentialBackoff.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,7 @@ private ExponentialBackoff() {
4040
* @return Duration representing the delay before the next retry
4141
*/
4242
public static Duration calculateDelay(int retryCount) {
43-
if (retryCount < 0) {
44-
return Duration.ZERO;
45-
}
46-
47-
// Calculate base delay: 2^retryCount * 100ms
48-
long baseDelayMs = (long) Math.pow(2, retryCount) * BASE_DELAY_MS;
49-
50-
// Cap at maximum delay
51-
long maxDelayMs = MAX_DELAY_SECONDS * 1000L;
52-
if (baseDelayMs > maxDelayMs) {
53-
baseDelayMs = maxDelayMs;
54-
}
55-
56-
// Add jitter: random value between baseDelay and 2 * baseDelay
57-
long minDelayMs = baseDelayMs;
58-
long maxDelayMsWithJitter = Math.min(baseDelayMs * 2, maxDelayMs);
59-
60-
// Generate random delay within the jitter range
61-
long jitterRange = maxDelayMsWithJitter - minDelayMs;
62-
long actualDelayMs = minDelayMs + (jitterRange > 0 ? (long) (RANDOM.nextDouble() * (jitterRange + 1)) : 0);
63-
64-
return Duration.ofMillis(actualDelayMs);
43+
return calculateDelay(retryCount, RANDOM);
6544
}
6645

6746
/**

0 commit comments

Comments
 (0)