feat: Implement circuit breaker pattern for external APIs
Implements comprehensive circuit breaker protection for Ozone API and
PDS blob downloads to prevent cascading failures during API degradation.
Changes:
- Created generic CircuitBreaker with states: Closed → Open → Half-Open → Closed
- Implemented three circuit breaker instances:
* Ozone API: 5 consecutive failures → open, 60s timeout, 1 success to close
* PDS Blob: 3 consecutive failures → open, 5m timeout, 1 success to close
* PLC Resolution: 3 consecutive failures → open, 5m timeout (created but not yet integrated)
Implementation Details:
- Circuit breaker checks added before all Ozone moderation API calls
- Circuit breaker checks added before PDS blob fallback downloads
- Automatic state transitions with configurable timeouts
- Thread-safe design using Arc<RwLock<>>
- Metrics tracking for state transitions and rejections
- Comprehensive unit tests covering all state transitions
Architecture:
- src/resilience/circuit_breaker.rs: Core circuit breaker implementation
- src/main.rs: Initialize three circuit breaker instances with metrics
- src/queue/worker.rs: Pass circuit breakers to moderation and download functions
- src/processor/matcher.rs: Circuit breaker protection for PDS blob downloads
- src/moderation/helpers.rs: Circuit breaker protection for Ozone API calls
- src/metrics/mod.rs: Track circuit_breaker_transitions and circuit_breaker_rejections
Tests:
- All 7 circuit breaker unit tests passing
- Verified state transitions (closed → open → half-open → closed)
- Tested failure threshold triggers opening
- Tested success during half-open closes circuit
- Tested failure during half-open reopens circuit
- Tested timeout calculation and half-open transition
- Tested half_open_max_calls limiting
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>