failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.17k stars 296 forks source link

Access wait time from failed attempt listener? #312

Closed jansohn closed 2 years ago

jansohn commented 2 years ago

I'd like to log the wait time until next run will be started. As we use withBackoff() this time is not a constant value. Any way this can be achieved?

RetryPolicy<Server> retryPolicy = new RetryPolicy<Server>()
    .handle(Throwable.class)
    .withBackoff(INITIAL_RETRY_DELAY_IN_SECONDS, MAX_RETRY_DELAY_IN_SECONDS, ChronoUnit.SECONDS)
    .withMaxAttempts(REGISTER_MAX_ATTEMPTS)
    .onFailedAttempt(listener -> log.warn("Registering server '{}' attempt #{} failed: '{}'. Retrying in {} seconds...",
            serverUrl,
            listener.getAttemptCount(),
            listener.getLastFailure().getMessage(),
            listener.getXXX()));

We're currently using failsafe 2.4.4.

jhalterman commented 2 years ago

This has come up before (#232) but I was waiting to see if there was much interest. There are some caveats though, which are described here: https://github.com/failsafe-lib/failsafe/issues/232#issuecomment-604218020. Any thoughts on those?

jansohn commented 2 years ago

This has come up before (#232) but I was waiting to see if there was much interest. There are some caveats though, which are described here: #232 (comment). Any thoughts on those?

Thanks, was searching for the wrong keywords I guess. Closing in favor of your issue and already left a comment there!