Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]Can withBackoff and withDelay be used at the same time? #369

Open
ripley opened this issue Oct 23, 2023 · 2 comments
Open

[Question]Can withBackoff and withDelay be used at the same time? #369

ripley opened this issue Oct 23, 2023 · 2 comments

Comments

@ripley
Copy link

ripley commented Oct 23, 2023

Say if I want to apply retry delay by increasing the retry interval exponentially for most cases, but for some specific exceptions like client error 429 I would like to calculate the delay by myself, is that possible by setting delay withBackoff and withDelay at the same time?

It appears this is not supported since delay will be overwritten but it'll be good if this can be confirmed.

Thanks for your attention.

@Tembrel
Copy link
Contributor

Tembrel commented Oct 23, 2023

You can't use both withDelay and withBackoff in the same RetryPolicy, since they use the same configuration fields internally.

But you can use a backoff delay in conjunction with a computed delay, e.g., (uncompiled, untested):

RetryPolicy retryPolicy = RetryPolicy.builder()
    // other stuff
    .withBackoff(...)
    .withDelayFn(context -> is429OrOtherSpecial(context) ? computeCustomDelay(context) : -1)
    .build();

I'm basing that idea on this Javadoc:

A negative return value will cause Failsafe to use a configured fixed or backoff delay

@ripley
Copy link
Author

ripley commented Oct 25, 2023

Thanks @Tembrel 👍 This works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants