Code Monkey home page Code Monkey logo

Comments (7)

michael-wolfenden avatar michael-wolfenden commented on May 18, 2024 19

SlyNet,

You could do this

Policy.Handle<Exception>(ex => !(exception is OperationCancelledException))

from polly.

reisenberger avatar reisenberger commented on May 18, 2024 2

Hi @kbabiy (Michael Wolfenden has stepped back from Polly by the way; the AppvNext team have now taken stewardship.)

I'll reflect further on an .Except(...) feature: I can see a syntax like this would suit some situations.

Aspects to think through would be how it played alongside the existing syntax. For instance, what would be meant by the following?

Policy
  .Handle<X>()
  .Or<Y>()
  .Except<A>()
  .Or<B>()

Should B be taken to be excluded or included by that? (And would the decision be clear to all users, whichever we chose?). It would probably be clearer to say that 'whitelisting' and 'blacklisting' exceptions could not be mixed, and 'all except' was an entirely alternative fluent stream. eg

Policy
  .HandleAllExcept<X>()
  .Or<Y>(); // Clearer here that Y is not handled?  

We'd also then need a way to combine that with the fact that Polly can also now handle return results. We probably wouldn't want to mix blacklisting and whitelisting in the same syntax, so result-handling would have to follow the 'all except' pattern too.

Policy
  .HandleAllExcept<X>()
  .Or<Y>()
  .AndAllResultsExcept<TResult>(...) 
  .OrResult<TResult>(...) // etc

Beginning to become quite complex to follow ...

We always have to consider whether extra API surface/complication adds sufficient benefit ... jury slightly still out for me on this one, given that there is already a workround (and taking into account the complex play with handling results). Very happy however for further community feedback on this.

from polly.

SlyNet avatar SlyNet commented on May 18, 2024

Yes, thanks. But fluent interface like Handle<Exception>().Except<OperationCancelledException> would be readable?

from polly.

michael-wolfenden avatar michael-wolfenden commented on May 18, 2024

SlyNet,

Thanks for you input, I will consider adding this. In the meantime, If you wanted to, your could add this as an extension method in your code.

from polly.

kbabiy avatar kbabiy commented on May 18, 2024

Hi, Michael

Something like .Except looks like a good feature to me as well.

Common case I have came across is not wanting to retry on Timeout.
Reasonings are:

  • Timeout quite probably means that requested resource is in trouble (working on top of its capacity) and adding retries makes things even worse (puts more stress on the resource already in stress, opens more long-hanging connections etc.)
  • You probably already don't need the result after (retryCount + 1)x timeouts has passed

Could you probably suggest better solution to handling this type of situation?

Thank you.

from polly.

reisenberger avatar reisenberger commented on May 18, 2024

@kbabiy Regarding other ways to handle the scenario:

Timeout quite probably means that requested resource is in trouble (working on top of its capacity)
and adding retries makes things even worse

... you have described the classic case for using a CircuitBreaker wrapping (or wrapped by) the Retry policy. See the very similar description about when retries become counter-productive, in the introductions to Retry and CircuitBreaker in the wiki.

Perhjaps consider wrapping a CircuitBreaker (perhaps breaking specifically on TimeoutException) in with your Retry.

from polly.

kbabiy avatar kbabiy commented on May 18, 2024

Hi, @reisenberger

Thank you for suggestion about CircuitBreaker. I know of this concept and reviewed it again after your suggestion, but i think it doesn't exactly fit (seems to be too radical) in my case, though generally makes a lot of sense in the similar scenarios.

As far as i understand problem with the Except originally proposed probably comes from the existing Or API being the only option to extend the Handle clause - therefore adding any And-like condition (like Except, AndNot, And etc.) leads to the unnecessary complex binary expressions being possible

Therefore adding the blacklisting approach (like HandleAllExcept) looks like a cleaner solution, even though needing symmetrical changes in the results handling (which probably also makes sense to extend with blacklisting).

Hopefully the benefit of such changes will overweight the needed API complications

from polly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.