Skip to content

pico-resilience v0.1.0

Latest

Choose a tag to compare

@dperezcabrera dperezcabrera released this 04 Jul 15:26

pico-resilience v0.1.0

First public release. Spring-style resilience annotations over pico-ioc method interception, auto-discovered by pico-boot. Zero-config. No prior versions; no migration required.

Decorators

Decorator Policy
@retryable(max_attempts, backoff_seconds, retry_on) Exponential-backoff retry (sync + async)
@circuit_breaker(failure_threshold, reset_timeout_seconds) Per-method circuit: closed → open → half-open
@timeout(seconds) Async time budget via asyncio.timeout

Highlights

  • Sync and async methods; failures raise typed exceptions (RetryExhaustedError, CircuitOpenError) carrying the method name.
  • Circuit state is per method, shared across instances, thread-safe; half-open allows exactly one trial call.
  • @timeout rejects sync methods at import time — a thread cannot be cancelled, and a timeout that lies is worse than none.
  • Chain rule (documented + pinned by a regression test): @retryable goes on top; @circuit_breaker/@cacheable below it wrap the whole retry loop.
  • resilience.enabled: false bypasses every policy (tests, local debugging).

Example

from pico_ioc import component
from pico_resilience import retryable, circuit_breaker

@component
class PaymentGateway:
    @retryable(max_attempts=3, backoff_seconds=0.2, retry_on=(ConnectionError,))
    @circuit_breaker(failure_threshold=5, reset_timeout_seconds=30)
    def charge(self, order): ...

Compatibility

  • Python 3.11+ · pico-ioc >= 2.2.0

Tests

  • 8 tests. Pinned behaviors: retry succeeds after transient failures (sync and async), non-matching exceptions propagate without retry, circuit opens/half-opens on schedule, @timeout rejects sync methods at decoration time, enabled: false bypasses every policy, and the chain rule (a policy below @retryable runs once per logical call, not per attempt).

Install

pip install pico-resilience