danielfm / pybreaker

Python implementation of the Circuit Breaker pattern.
BSD 3-Clause "New" or "Revised" License
512 stars 74 forks source link

Add CircuitBreakerMultiplexer #32

Open Timvde opened 6 years ago

Timvde commented 6 years ago

It might happen that a particular subsystem only partially fails. For example, a specific call to an external service might be broken, while other calls still work. In that case, it might be undesirable to disable the entire subsystem. This multiplexer allows to dynamically create a CircuitBreaker based on a method argument.

We needed this in our company, so grab it if you like it :)

Timvde commented 6 years ago

Hmm, it does not seem to be Python 2 compatible. We are only using 3.6, so I didn't test this. The failures in Python < 3.4 seem to be unrelated.

If you are willing to take this upstream, I'll invest time into making it work on Python 2.7.

Timvde commented 6 years ago

I just discovered an edge case (fix pushed). I'm going further down the Python 3 only route here, though, since my fix is also using introspection functionality that Python 2 just doesn't offer.

As a compromise, I think it would be easiest to leave out support for positional arguments in Python 2 code and only support Python 3. In Python 2, the caller would then be forced to use a keyword argument when calling the function.

I do hope I'm not missing any other edge cases. If you see any, I'm all ears!

Timvde commented 6 years ago

Found a minor mistake in one of my test cases too. No changes to the code itself. I just amended the fix to the first commit.