August 2018
Intermediate to advanced
248 pages
5h 51m
English
We are going to use the pybreaker library. You can install it in your Python, via the pip install pybreaker command.
Let's say you want to use a circuit breaker on a flaky function (for example, fragile due to the networking environment it depends on).
Our implementation is inspired by a nice script I found in this repository: https://github.com/veltra/pybreaker-playground, which we will adapt.
Here is our version of the function to simulate fragile calls:
def fragile_function(): if not random.choice([True, False]): print(' / OK', end='') else: print(' / FAIL', end='') raise Exception('This is a sample Exception')
Let's define our cirbuit breaker to automatically open the circuit after five consecutive failures in that function. ...