GithubHelp home page GithubHelp logo

Comments (2)

martintmk avatar martintmk commented on June 9, 2024

Hey @IGx89

In Polly V8 there is no way to retrieve the circuit breaker state from an instance of ResiliencePipeline. Even if enumerating pipeline from registry was available it wouldn't help.

What you want to do is to keep registry of CircuitBreakerStateProvider as you are creating the pipelines. See this test that demonstrates your use-case:

// Arrange
var states = new ConcurrentBag<CircuitBreakerStateProvider>();
using var registry = new ResiliencePipelineRegistry<string>();

// Act
_ = registry.GetOrAddPipeline("A", builder =>
{
    var stateProvider = new CircuitBreakerStateProvider();
    builder.AddCircuitBreaker(new() { StateProvider = stateProvider });
    states.Add(stateProvider);
});

_ = registry.GetOrAddPipeline("B", builder =>
{
    var stateProvider = new CircuitBreakerStateProvider();
    builder.AddCircuitBreaker(new() { StateProvider = stateProvider });
    states.Add(stateProvider);
});

_ = registry.TryAddBuilder("C", (builder, _) =>
{
    var stateProvider = new CircuitBreakerStateProvider();
    builder.AddCircuitBreaker(new() { StateProvider = stateProvider });
    states.Add(stateProvider);
});

// Assert
states.Should().HaveCount(2);
registry.GetPipeline("C");
states.Should().HaveCount(3);

foreach (var state in states)
{
    state.CircuitState.Should().Be(CircuitState.Closed);
}

doesn't implement IEnumerable nor provides any way to get a list of the pipelines. Was that removed deliberately? If not, could that functionality be added back?

This was deliberate choice due to dynamic nature of registry. The pipelines are not explicitly added, instead these are created on demand when requested. Additionally, with the minimal nature of ResiliencePipeline there is now way to retrieve any information about strategies from it.

Also created a PR that adds this test: #1829

from polly.

IGx89 avatar IGx89 commented on June 9, 2024

Thanks a lot for the detailed explanation and code example! That's very helpful. I definitely have a lot more learning to do it looks :)

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.