circuitbreaker icon indicating copy to clipboard operation
circuitbreaker copied to clipboard

Listener to control the change of the circuit state

Open sergioave opened this issue 2 years ago • 3 comments

I would like to know if you have in the roadmap the implementation of some kind of listener to control the state changes of the circuits, I think it is very interesting and especially useful for metric control.

Would you be open to any kind of contribution?.

We have been develop a first version using inheritance.

def state_change(self, old_state, new_state):
    # Called when the circuit breaker state changes.
    pass

def before_callfunc(self, func,  *args, **kwargs):
    # Called before the circuit breaker decorated function has been called
    pass

def succes(self):
    # Called when the circuit breaker decorated function finished ok"
    pass

def failure(self, exc_type, exc_value, _traceback):
    # Called when the circuit breaker decorated function finished with selected exception"
    pass

Best regards

sergioave avatar Sep 21 '23 09:09 sergioave

I've been looking for something like this as well. Would be great to be able to send notifications when a circuit changes state for monitoring purposes...

ramykl avatar Sep 25 '23 10:09 ramykl

Just in case, I noticed that there is a competing library called pybreaker that implements that feature: https://github.com/danielfm/pybreaker#event-listening

EDIT: the other library doesn't seem to support coroutines, this one does!

eliasdorneles avatar Sep 26 '23 19:09 eliasdorneles

Just in case, I noticed that there is a competing library called pybreaker that implements that feature: https://github.com/danielfm/pybreaker#event-listening

EDIT: the other library doesn't seem to support coroutines, this one does!

The interface we have been testing to contribute is similar to pybreaker but instead of listener we use inheritance.

sergioave avatar Sep 27 '23 07:09 sergioave