pybreaker
pybreaker copied to clipboard
Implement _exceptions list
Hi All,
it would be nice if function is_system_error can work with self._exceptions as well. I am about to implement ES circuit breaker for just one exception (ES BROKEN CONNECTION) so that I have to create my own Breaker (subclassing CircuitBreaker) and rewrite function is_system_error instead of just define one exception in the new list self._exceptions.
Regards, Vojtech.
Yes, I needed something similar and ended up using a callable that check that the error is of the type i want. But that functionality is only in the latest master, not in a release
Now that some time has passed, it's simple to do this as sebastiandev has said
Including a test for this here, modeled after the existing tests in tests.py:
def test_allow_whitelist(self):
"""CircuitBreaker: it should allow the user to add a predicate function to determine excluded exceptions.
"""
acceptableExceptions = [NotImplementedError]
isUnacceptableException = lambda e: type(e) not in acceptableExceptions
self.breaker = CircuitBreaker(exclude=[isUnacceptableException])
def throwsAcceptableError(): raise NotImplementedError
def throwsUnacceptableError(): raise LookupError
self.assertRaises(NotImplementedError, self.breaker.call, throwsAcceptableError)
self.assertEqual(1, self.breaker.fail_counter)
self.assertRaises(LookupError, self.breaker.call, throwsUnacceptableError)
self.assertEqual(0, self.breaker.fail_counter)
Also this issue seems to be a copy of #5, so probably one of them should be closed?