Open pandoras-toolbox opened 9 months ago
Doesn't FailsafeExecutor::run(ContextualRunnable<Void>)
give you that already?
Failsafe.with(...)
.run(ctx -> {
int count = ctx.getExecutionCount();
... do stuff with count, maybe throw checked exception ...
});
As far as I know, the ExecutionEvent
types just offer subsets of ExecutionContext
information.
Oh, yes, you are right, I overlooked that method. Thank you!
But one question, I cannot obtain the duration for the next attempt? I wanted to log that it will wait now for that duration until retrying again.
You can configure an OnRetryScheduled event listener on the retry policy, and use event.getDelay()
. See:
https://failsafe.dev/retry/#event-listeners https://failsafe.dev/javadoc/core/dev/failsafe/RetryPolicyBuilder.html#onRetryScheduled-dev.failsafe.event.EventListener-
Thank you. I cannot do exactly what I wanted in an elegant way because the information is not available in the run(...) block, but nevermind.
There's no way, elegant or otherwise, to supply the delay before the next execution attempt within the current attempt, because you don't in general know whether the current attempt will be seen as a failure or, if a delay function is used, what delay will be computed. (The delay function can use the result of the failed attempt to determine the delay.)
Okay, I see.
A suggestion about the method FailsafeExecutor#run(dev.failsafe.function.CheckedRunnable) and the similar get method.
I think it would be nice if a ExecutionEvent variable would be available like in the method RetryPolicyBuilder#onFailedAttempt(...)
There are some things which you cannot do with the available features of Failsafe if there is no such information in the execution block itself, I mean without workarounds or doing it in an awkward way.
What do you think?