Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions services/circuit_breaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class CircuitBreaker:
"""Consecutive-failure breaker: closed -> open (after N fails) -> half-open (after cooldown)."""
"""Consecutive-failure breaker: closed, opens after N fails, half-opens to probe after a cooldown."""

def __init__(
self,
Expand Down Expand Up @@ -55,9 +55,9 @@ def record_success(self) -> None:
def record_failure(self) -> bool:
"""Count a failed call.

Returns True iff this failure *just* tripped the breaker open (callers
can use that edge to emit a one-shot notification). A failed half-open
probe restarts the cooldown but does not re-trip.
Returns True iff this failure *just* tripped the breaker into the open
state, so callers can emit a one-shot notification on that edge. A failed
half-open probe restarts the cooldown but does not re-trip.
"""
with self._lock:
self._failures += 1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_circuit_breaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_closed_until_threshold_then_opens():
assert br.record_failure() is False # 1
assert br.record_failure() is False # 2
assert br.allow() # still closed below threshold
assert br.record_failure() is True # 3 -> trips open (edge)
assert br.record_failure() is True # 3 -> trips it open at threshold
assert not br.allow() # open, within cooldown
assert br.is_open

Expand Down
Loading