Skip to content

Commit 6e79f2e

Browse files
feat: adding circuit breaker feature
1 parent 03dc429 commit 6e79f2e

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

docs/utilities/circuit_breaker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ Register an `on_circuit_open` callback to decide what happens to a rejected requ
149149

150150
If no callback is registered, an open circuit raises `CircuitBreakerOpenError`. Catch it to decide how to respond. The exception carries a `circuit` attribute (`CircuitInfo`) so you can inspect why the request was rejected.
151151

152-
=== "working_with_custom_config.py"
152+
=== "working_without_callback.py"
153153

154154
```python hl_lines="5 16-22 38-43"
155-
--8<-- "examples/circuit_breaker_alpha/src/working_with_custom_config.py"
155+
--8<-- "examples/circuit_breaker_alpha/src/working_without_callback.py"
156156
```
157157

158158
## Configuration

examples/circuit_breaker_alpha/src/getting_started_with_circuit_breaker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class PaymentBackend:
14-
def charge(self, order: dict) -> dict: ...
14+
def charge(self, order: dict): ...
1515

1616

1717
payment_api = PaymentBackend()

examples/circuit_breaker_alpha/src/working_with_callback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class PaymentBackend:
19-
def charge(self, order: dict) -> dict: ...
19+
def charge(self, order: dict): ...
2020

2121

2222
payment_api = PaymentBackend()

examples/circuit_breaker_alpha/src/working_with_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def emit_transition_metric(transition: CircuitTransition) -> None:
2626

2727

2828
class PaymentBackend:
29-
def charge(self, order: dict) -> dict: ...
29+
def charge(self, order: dict): ...
3030

3131

3232
payment_api = PaymentBackend()

examples/circuit_breaker_alpha/src/working_with_custom_config.py renamed to examples/circuit_breaker_alpha/src/working_without_callback.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
class PaymentBackend:
27-
def charge(self, order: dict) -> dict: ...
27+
def charge(self, order: dict): ...
2828

2929

3030
payment_api = PaymentBackend()
@@ -40,4 +40,5 @@ def lambda_handler(event: dict, context: LambdaContext):
4040
return charge(event)
4141
except CircuitBreakerOpenError as exc:
4242
# No callback registered, so we decide what to do with the rejected request here.
43-
return {"statusCode": 202, "circuit": exc.circuit.name}
43+
circuit_name = exc.circuit.name if exc.circuit else "unknown"
44+
return {"statusCode": 202, "circuit": circuit_name}

0 commit comments

Comments
 (0)