Raxol.Core.ErrorRecovery (Raxol v2.0.1)
View SourceError recovery strategies for the Raxol application.
Provides various recovery mechanisms for different types of errors, including circuit breakers, fallback mechanisms, and graceful degradation.
REFACTORED: All try/catch/rescue blocks replaced with functional patterns.
Features
- Circuit breaker pattern for external services
- Fallback strategies
- Graceful degradation
- Resource cleanup on errors
- State recovery mechanisms
Summary
Functions
Returns a specification to start this module under a supervisor.
Initializes a circuit breaker with optional configuration.
Resets a circuit breaker to its initial state.
Gets the current state of a circuit breaker.
Implements graceful degradation for feature availability.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.
Implements bulkhead pattern to isolate failures.
Executes a function with circuit breaker protection.
Ensures cleanup is performed even on error.
Provides fallback mechanism for failed operations.
Implements exponential backoff retry strategy.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Initializes a circuit breaker with optional configuration.
Resets a circuit breaker to its initial state.
Gets the current state of a circuit breaker.
Implements graceful degradation for feature availability.
This is now a regular function instead of a macro to avoid try/rescue.
Examples
degrade_gracefully(:advanced_search,
fn -> AdvancedSearch.execute(query) end,
fn -> BasicSearch.execute(query) end
)
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.
Implements bulkhead pattern to isolate failures.
Executes a function with circuit breaker protection.
Examples
with_circuit_breaker(:external_api, fn ->
ExternalAPI.call()
end)
Ensures cleanup is performed even on error.
Examples
with_cleanup fn ->
resource = acquire_resource()
process(resource)
end, fn resource ->
release_resource(resource)
end
Provides fallback mechanism for failed operations.
Examples
with_fallback fn ->
fetch_from_primary()
end, fn ->
fetch_from_cache()
end
Implements exponential backoff retry strategy.
Options
:max_retries- Maximum number of retry attempts (default: 3):base_delay- Base delay in milliseconds (default: 100):max_delay- Maximum delay in milliseconds (default: 5000):jitter- Add randomness to delays (default: true)