How to use circuitbreaker - 5 common examples

To help you get started, we’ve selected a few circuitbreaker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuker / django-patchboard / patchboard / tests.py View on Github external
def test_breaker(self):
        class MyBreaker(CircuitBreaker):
            def run(self):
                assert not getattr(self, 'fail', False)
        
        breaker = MyBreaker(4, 600)
        self.assertTrue(breaker.is_ready())
        breaker()
        self.assertFalse(breaker.failures)
        breaker.open_circuit()
        self.assertFalse(breaker.is_ready())
        breaker.error_expiration = datetime.datetime.now()
        breaker()
        self.assertTrue(breaker.is_ready())
        breaker.fail = True
        for i in range(3):
            try:
                breaker()
github cuker / django-patchboard / patchboard / tests.py View on Github external
for i in range(3):
            try:
                breaker()
            except AssertionError:
                self.assertTrue(breaker.is_ready())
            else:
                self.fail('Should have raised an exception')
        try:
            breaker()
        except AssertionError:
            self.assertFalse(breaker.is_ready())
        else:
            self.fail('Should have raised an exception')
        try:
            breaker()
        except CircuitOpen:
            pass
        else:
            self.fail('Wrong exception?')
        breaker.error_expiration = datetime.datetime.now()
        try:
            breaker()
        except:
            pass
        self.assertFalse(breaker.is_ready()) #we failed so we're not ready yet
        breaker.fail = False
        breaker.error_expiration = datetime.datetime.now()
        breaker()
        self.assertTrue(breaker.is_ready())
github morganjbruce / microservices-in-action / chapter-11 / market / app.py View on Github external
    @circuit(failure_threshold=5, expected_exception=ConnectionError)
    def __place_order_exchange(self, request):
        print("[{}] {} placing order to stock exchange".format(
            request, self.name))
        response = requests.get('https://jsonplaceholder.typicode.com/posts/1')
        return json.dumps({'code': response.status_code, 'body': response.text})
github morganjbruce / microservices-in-action / chapter-12 / market / app.py View on Github external
    @circuit(failure_threshold=5, expected_exception=ConnectionError)
    def __place_order_exchange(self, uuid):
        self.logger.info("placing order in the exchange", extra={
            "uuid": uuid})

        response = requests.get('https://jsonplaceholder.typicode.com/posts/1')
        return json.dumps({'code': response.status_code, 'body': response.text})
github morganjbruce / microservices-in-action / chapter-7 / feature / market / app.py View on Github external
    @circuit(failure_threshold=5, expected_exception=ConnectionError)
    def __place_order_exchange(self, request):
        print("[{}] {} placing order to stock exchange".format(
            request, self.name))
        response = requests.get('https://jsonplaceholder.typicode.com/posts/1')
        return json.dumps({'code': response.status_code, 'body': response.text})

circuitbreaker

Python Circuit Breaker pattern implementation

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

61 / 100
Full package analysis