How to use the aiomisc.circuit_breaker.CircuitBreakerStates 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 / aiomisc / circuit_breaker.py View on Github external
if (
            self._state is CircuitBreakerStates.PASSING
            and len(self._statistic) < self.BUCKET_COUNT
        ):
            return

        recovery_ratio = self.recovery_ratio

        if self._state is CircuitBreakerStates.PASSING:
            if recovery_ratio >= self.PASSING_BROKEN_THRESHOLD:
                self._stuck_until = current_time + self._broken_time
                self._state = CircuitBreakerStates.BROKEN
                self._statistic.clear()
            return

        if self._state is CircuitBreakerStates.RECOVERING:
            if recovery_ratio >= self.RECOVER_BROKEN_THRESHOLD:
                self._stuck_until = current_time + self._broken_time
                self._state = CircuitBreakerStates.BROKEN
                self._statistic.clear()
                return

            recovery_length = current_time - self._recovery_at
            if recovery_length >= self._recovery_time:
                self._stuck_until = current_time + self._passing_time
                self._state = CircuitBreakerStates.PASSING
                return
github aiokitchen / aiomisc / aiomisc / circuit_breaker.py View on Github external
def _exec(self):
        counter = self.counter()
        self._compute_state()

        if self._state is CircuitBreakerStates.PASSING:
            yield from self._on_passing(counter)
            return

        elif self._state is CircuitBreakerStates.BROKEN:
            yield from self._on_broken()
            return

        elif self._state is CircuitBreakerStates.RECOVERING:
            yield from self._on_recover(counter)
            return

        raise NotImplementedError(self._state)