How to use the aiomisc.circuit_breaker.CircuitBroken function in aiomisc

To help you get started, we’ve selected a few aiomisc 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 aiokitchen / aiomisc / tests / test_circuit_breaker.py View on Github external
assert circuit_breaker.recovery_ratio == 0
    assert circuit_breaker.state == States.PASSING

    ctx.failed = True

    for _ in range(10):
        await asyncio.sleep(0.05)

        with pytest.raises(RuntimeError):
            circuit_breaker.call(ctx)

    for _ in range(10):
        try:
            circuit_breaker.call(ctx)
        except (RuntimeError, CircuitBroken):
            pass

    assert circuit_breaker.state == States.BROKEN
github aiokitchen / aiomisc / aiomisc / circuit_breaker.py View on Github external
def _on_recover(self, counter):
        current_time = time.monotonic()
        condition = (random() + 1) < (
            2 ** ((current_time - self._recovery_at) / self._recovery_time)
        )

        if condition:
            yield from self._on_passing(counter)
        else:
            raise CircuitBroken()