Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 10 19:02

    jhalterman on gh-pages

    Fix who's using page edit link (compare)

  • Aug 24 01:54
    ben-manes commented #47
  • Aug 24 00:24
    jhalterman commented #47
  • Aug 24 00:21
    jhalterman commented #47
  • Aug 24 00:21
    jhalterman commented #47
  • Aug 23 19:50
    ben-manes commented #47
  • Aug 23 18:48
    jhalterman commented #47
  • Aug 23 18:47
    jhalterman commented #47
  • Aug 23 04:21
    AvaPL commented #206
  • Aug 23 03:14
    jhalterman commented #203
  • Aug 23 03:14
    jhalterman commented #206
  • Aug 23 03:14
    jhalterman commented #204
  • Aug 22 22:59

    jhalterman on gh-pages

    Add toc for small displays Twea… (compare)

  • Aug 22 22:56

    jhalterman on gh-pages

    Updated JavaDocs (compare)

  • Aug 22 22:54

    jhalterman on master

    [maven-release-plugin] prepare … (compare)

  • Aug 22 22:54

    jhalterman on failsafe-2.3.1

    (compare)

  • Aug 22 22:54

    jhalterman on master

    [maven-release-plugin] prepare … (compare)

  • Aug 22 22:53

    jhalterman on master

    Updated changelog (compare)

  • Aug 22 22:49
    jhalterman commented #202
  • Aug 22 22:49
    jhalterman commented #202
Jonathan Halterman
@jhalterman
@danzik You can use a DelayFunction to compute a delay based on the last execution result, if you'd like
Daniil Gaidukov
@danzik
@jhalterman do you have some example?
maybe we can use some listener? I'm just don't know where I can find it...
that's the method you'd use to configure a delay function, which should have the inputs you need to return an appropriate delay
Daniil Gaidukov
@danzik
and how should I set it for CB? Thx for thre propose, @jhalterman !
Jonathan Halterman
@jhalterman
i'm not sure what you mean by throttling - is that one of your exceptions? but i was thinking something like:
circuitBreaker.withDelay((r, f, ctx) -> {
  if (failure instanceof ThrottlingException)
    return Duration.ofSeconds(5);
  else
    return null;
});
Daniil Gaidukov
@danzik
yes, it's smth similar with aws ThrottlingException.
I'll try to use it, and if everything will work fine, will write to you) Thanks @jhalterman !
Jonathan Halterman
@jhalterman
or even shorter:
circuitBreaker.withDelayOn((r, f, ctx) -> {
    return Duration.ofSeconds(5);
}, ThrottlingException.class);
no problem
Jonathan Halterman
@jhalterman

I just pushed support for a new Timeout policy and execution cancellation:

https://github.com/jhalterman/failsafe#timeouts
https://github.com/jhalterman/failsafe#execution-cancellation

Feel free to try these out in master. I plan to cut a 2.2.0 release in a day or two unless anyone has objections or uncovers anything major.
Daniil Gaidukov
@danzik
@jhalterman how can I handle custom exception cases for CircuitBreaker? For instance for CB: failure threshold is 10 of 10 and I want to execute some logic after that, maybe do you have som listener for that?
Jonathan Halterman
@jhalterman
@danzik To configure the breaker to handle custom exceptions: breaker.handle(MyException.class), .handleIf, etc. CircuitBreaker extends FailurePolicy: https://jodah.net/failsafe/javadoc/net/jodah/failsafe/FailurePolicy.html
To execute some logic after each time an execution fails in the breaker: breaker.onFailure(e -> ...). If your failureThreshold was 10/10, this would get executed 10 times in a row before the breaker is opened.
To execute some logic after all 10/10 executions fail and the breaker is opened, which I think is what you want: breaker.OnOpen(() -> ....).
Does that help?
Daniil Gaidukov
@danzik

yes, exactly! Thank you @jhalterman !

breaker.onFailure(e -> ...). If your failureThreshold was 10/10, this would get executed 10 times in a row before the breaker is opened.

Maxim Kolesnikov
@xCASx

Hello. In previously posted example I defined RetryPolicy like this:

        new RetryPolicy<Optional<Cluster>>()
            .withDelay(DELAY_BETWEEN_RETRIES)
            .withMaxRetries(MAX_RETRIES)
            .handle(Arrays.asList(RuntimeException.class, IOException.class))
            .handleResult(Optional.empty())
            .abortOn(GeneralSecurityException.class)
            .onFailedAttempt(e -> LOG.warn("Error message", e.getLastFailure()));

My intention was to log an exception if an attempt failed. But neither onFailedAttempt nor onFailurecontains any failure if the exception is handled (RuntimeException or IOException in my case). How to properly log those?

Jonathan Halterman
@jhalterman
@xCASx When you have multiple handle conditions, they are applied using an OR operator. So your retry policy would consider an execution a failure if it threw RuntimeException, IOException OR returned Optional.empty.
If the result was Optional.empty, then onFailedAttempt is still called with the getLastResult() being Optional.empty and getLastFailure being null
If your RetryPolicy is only configured to handle exceptions and onFailedAttempt is not showing an exception, then that's a bug :)
Maxim Kolesnikov
@xCASx
@jhalterman I actually had a ClassCastException in my code, but still onFailedAttempt didn't show it as a cause. It returned empty optional instead. So the throwable was swallowed.
This all happens in integration test scenario, so it is reproducible. I may spend a bit more time debugging tomorrow.
Jonathan Halterman
@jhalterman
@xCASx Yes, please if you can write a small reproducer test and file an issue, that would be great.
Maxim Kolesnikov
@xCASx
@jhalterman nevermind, it was my bad. Fallback was defined after retry, but should be vice versa, as the order matters.
Jonathan Halterman
@jhalterman
Failsafe 2.2.0 is (finally) released, and includes timeout support!
Daniil Gaidukov
@danzik

@jhalterman faisafe has some methods or listener which will handle exception if handleIf method returns true? for instance, I have configuration for CB

    CircuitBreaker<Response> breaker = new CircuitBreaker<>();
    breaker.withFailureThreshold(..., ...);
    breaker.withSuccessThreshold(..., ...);
    breaker.handleIf(throwable -> {
        if (throwable insanceOf myException) {
            return true;
        } 
        return false;
    })

and in code

methodName() {
    ...
    breaker.recordFailure(new myException("..."));
    ...
}

I know about handleIf method, but it will not work for that, only if in CB smth. happend. Thanks!

Jonathan Halterman
@jhalterman
You should be able to use handleIfwith a RetryPolicy or Fallback as well - is it not working?
I'm not sure if you mean you want to manually record failures, similar to breaker.recordFailure? In that case you can wrap a Policy in an Execution class: https://github.com/jhalterman/failsafe/#execution-tracking
Daniil Gaidukov
@danzik
I'm not sure if you mean you want to manually record failures, similar to breaker.recordFailure?
no, I want to do my custom logic when I'll get myException type exception. Like I undestand we shoud it handle in handleIf method, correct if I'm wrong.
Jonathan Halterman
@jhalterman
@danzik So you want a way to have custom logic that is called when handleIf returns true?
Daniil Gaidukov
@danzik
@jhalterman yes, smth similar with that. I think it will be good to have some listener or smth similar for that, what do you think about that?
Jonathan Halterman
@jhalterman
couldn't you put whatever code you want inside the handleIf method?
breaker.handleIf(t -> {
  if (t instanceof MyException) {
   doSomeThings();
   return true;
  }
  return false;
});
Daniil Gaidukov
@danzik
sure, I can, but I thought maybe failsafe has a separate method for that or listener.
@jhalterman anyway thx for the response!
Jonathan Halterman
@jhalterman
Well those handle methods are meant to return pretty quickly and not do much other work. But you could use it in this way if you like.
Jonathan Halterman
@jhalterman
Released Failsafe 2.3.0, with a fix for Timeout interrupts and a change that no longer wraps synchronous Errors in FailsafeException. https://github.com/jhalterman/failsafe/blob/master/CHANGES.md
Jonathan Halterman
@jhalterman
There's a new Failsafe website: http://jodah.net/failsafe/
Hopefully this makes reading the docs a bit easier. Feedback welcome.
Maxim Kolesnikov
@xCASx
@jhalterman good job!
Willi Schönborn
@whiskeysierra
Very nice indeed
Jonathan Halterman
@jhalterman
Thanks :thumbsup:
Jonathan Halterman
@jhalterman
Actually having a proper website is allowing me to fill in a bit more info where before I didn't want the README to get too long.
Jonathan Halterman
@jhalterman
Released 2.3.1 with a few minor fixes/improvements https://github.com/jhalterman/failsafe/blob/master/CHANGES.md#231
Ilja S
@iljasss_twitter
Hello, very useful lib. One question, is that possible to throw an original exception on failure (or when retries exceeded) instead of FailsafeException?
Jonathan Halterman
@jhalterman
@iljasss_twitter Yes - FailsafeException is only thrown if the original exception is a checked Exception. This is necessary because the API does not declare throws Exception, so it wraps the original exception in FailsafeException when necessary. If the original exception is a RuntimeException it will not be wrapped and will be thrown directly.
Ilja S
@iljasss_twitter
Oh, ok thank you!