Closed alukach closed 7 years ago
Thanks for jumping in on this one!
@jcwilson Thanks for the helpful input, I agree on almost all comments except for the optimization comment (I will change it if you twist my arm, but I prefer it as is).
@jcwilson Thanks for the helpful input, I agree on almost all comments except for the optimization comment (I will change it if you twist my arm, but I prefer it as is).
Nope, no arm twisting - just offering a perspective. :)
Thinking about this, I think some things aren't right with my current implementation. Giving it a once over and then will re-open.
Questions:
_state_storage
changes or should we notify listeners once-per-environment?I believe the answers are 1) Send notifications once-per-environment, 2) Send notification on fallback states as well. Basically, notifications will inform when a particular instance notices a circuit being closed due to a down service, rather than when the service is first noticed to be down. The only exception to this is when the CircuitBreaker
is being initialized, in which case it does not notify of a new state.
Okay, code should be a bit better now. I realized that I was incorrectly sending the new state to the state classes (e.g. CircuitOpenState
) rather than the previous state. While in there, I was getting a bit confused about having both the CircuitBreaker
and CircuitBreakerState
hold state about the status of the breaker. I think I've simplified it quite a bit, leaving the logic more-or-less the same but making it clearer what the roles of CircuitBreaker.state
was.
@jcwilson @danielfm So any final thoughts on this? What are the odds that this could be merged in and release? I have a feature that depends on this change so I'm hoping we can get it released soon.
1) Send notifications once-per-environment
If this is the same as once per process, then I concur. Users of the library can perform their own deduplication or specialized handling in their Listener classes.
2) Send notification on fallback states as well.
I think this is fine. I'd rather know that my app has changed states, regardless of why.
Thanks for your contribution, I just uploaded the 0.4.1 release to PyPI.
The PR intends to resolve danielfm/pybreak#26 by altering the
CircuitBreaker
to make no assumptions about an initializedCircuitBreaker
state. Instead, on first call ofbreaker.state
, the state is retrieved from thestate_storage
. This allowspybreaker
to play nicely in environments where it is desirable shareCircuitBreaker
state between machines.