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

Asynchronous retries 'whenFailure' broken in 0.4? #5

Closed
Haardt opened this issue Oct 23, 2015 · 4 comments
Closed

Asynchronous retries 'whenFailure' broken in 0.4? #5

Haardt opened this issue Oct 23, 2015 · 4 comments
Labels

Comments

@Haardt
Copy link

Haardt commented Oct 23, 2015

Hi,
when the retry policy is exceeded, the failure function is not called. Can you make a new release of the master brunch? - (perhaps the bug is corrected.)

retryPolicy = new RetryPolicy()
         .withDelay(100, TimeUnit.MILLISECONDS)
         .withMaxDuration(2, TimeUnit.SECONDS)
         .withMaxRetries(3);

RecurrentFuture<?> run = Recurrent.get(() -> {
  doAnything();
  return <<>>;
}, retryPolicy, executer);
run.whenFailure ( error -> System.out.println("timeout"));
@jhalterman
Copy link
Member

Your listener should only get called if doAnything throws an exception. I just pushed a test to verify this behavior and things seem to be working as expected. Two things to note:

The current API in master is a bit different than from the last release. The listener now accepts a result and a failure since failure could indicate an exception being thrown or a bad result being returned. That said, the listener is called as expected in the test.

Let me know what you think.

@Haardt
Copy link
Author

Haardt commented Oct 26, 2015

I assumed that a exceeded retry policy would trigger the failure event. I use your library on a udp protocol, since there is not always a result. My solution at the moment is that I check the result to be present. If there no result, it must be a timeout. A "retryExceeded"-Handler would be nice.

Thank you!

@jhalterman
Copy link
Member

@Haardt I know this is an old issue, but I wanted to dig it back up again to make sure I understand your use case. Basically, you'd like your failure handler to be called if retries are exceeded and some unexpected result occurred? The unexpected result bit is important because that's how Recurrent knows to keep trying. Maybe an example policy:

retryPolicy = new RetryPolicy()
         .withDelay(100, TimeUnit.MILLISECONDS)
         .withMaxDuration(2, TimeUnit.SECONDS)
         .withMaxRetries(3)
         .whenResult(null);

This would perform retries so long as the result is null and the whenFailure handler would be called if a non-null result is never returned. Does this work for you?

@jhalterman
Copy link
Member

Also - See the new event listeners API that allows you to listen specifically for onCompleted, onFailed, etc. events:

https://github.com/jhalterman/recurrent#event-listeners

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

No branches or pull requests

2 participants