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

Initial wait time in an exponential retry strategy. #86

Open
jcranston opened this issue Jun 15, 2018 · 3 comments
Open

Initial wait time in an exponential retry strategy. #86

jcranston opened this issue Jun 15, 2018 · 3 comments

Comments

@jcranston
Copy link

Is there a way to initialize the wait strategy to be a fixed amount of time? As in, all successive exponential wait times are added onto a fixed wait time. For example, the computeSleepTime for the exponential wait strategy which is currently

@Override
public long computeSleepTime(Attempt failedAttempt) {
    double exp = Math.pow(2, failedAttempt.getAttemptNumber());
    long result = Math.round(multiplier * exp);
    if (result > maximumWait) {
        result = maximumWait;
    }
    return result >= 0L ? result : 0L;
}

can return something like initialWait + (result >= 0L ? result : 0L)?

Perhaps this can already be accomplished in another way?

@rhuffman
Copy link

I think the closest option is this method in WaitStrategies:

    public static WaitStrategy exponentialWait(long multiplier,
                                               long maximumTime,
                                               @Nonnull TimeUnit maximumTimeUnit)

The exponential wait is normally in milliseconds. If you know your operation typically takes, say, 800 ms, then you would do something like this:

WaitStrategy = exponentialWait(1000, 5, TimeUnit.MINUTES);

That way your waits would be in seconds instead of milliseconds.

@jcranston
Copy link
Author

Ah, interesting. Upon digging, I'm assuming it would also suffice to use the CompositeWaitStrategy as well, with a ExponentialWaitStrategy and FixedWaitStrategy.

@valera7979
Copy link

It is inconvenient. It is logical to use fixed start time and maximum time. For example, when I have a disconnection issue I want to retry after 5 seconds and exponentially increase every next attempt. Why do I need to calculate time to wait?

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

3 participants