Skip to content

Conversation

jhl221123
Copy link
Contributor

@jhl221123 jhl221123 commented May 15, 2025

This PR introduces a jitter parameter to the @Retryable annotation, as requested in issue #11631.

Closes #11631

@graemerocher graemerocher requested a review from yawkat May 15, 2025 15:59
@injae-kim injae-kim mentioned this pull request May 17, 2025
* @return The jitter factor used to apply random deviation to retry delays
*/
@Digits(integer = 1, fraction = 2)
String jitter() default "0.25";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String jitter() default "0.25";
String jitter() default "0.0";

should be set default jitter to 0? (jitter 0 means don't apply jitter by default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a valid point. Thank you for the suggestion!

@@ -173,6 +187,10 @@ public Class<? extends Throwable> getCapturedException() {
public long nextDelay() {
double multiplier = getMultiplier().orElse(1.0);
long delay = (long) ((getDelay().toMillis()) * pow(multiplier, attemptNumber.get() - 1));
double jitter = getJitter().orElse(0);
if(jitter > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(jitter > 0) {
if (jitter > 0) {

nit. indent

/**
* @return The jitter factor used to apply random deviation to retry delays
*/
OptionalDouble getJitter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs default impl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've updated the PR to include the default implementation.
I'd appreciate any further comments you might have.

@yawkat yawkat added this to the 4.9.0 milestone May 19, 2025
@yawkat yawkat added the type: improvement A minor improvement to an existing feature label May 19, 2025
@yawkat yawkat merged commit 721c475 into micronaut-projects:4.9.x May 19, 2025
16 checks passed
@yawkat
Copy link
Member

yawkat commented May 19, 2025

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

@Retryable jitter
3 participants