Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)