Snakepit.Executor (Snakepit v0.8.7)
View SourceExecution helpers with retry, circuit breaker, and timeout support.
Provides various execution strategies for running operations with fault tolerance.
Usage
# Simple execution with retry
result = Executor.execute_with_retry(
fn -> risky_operation() end,
max_attempts: 3,
backoff_ms: [100, 200, 400]
)
# With circuit breaker
result = Executor.execute_with_circuit_breaker(cb, fn ->
external_call()
end)
# With timeout
result = Executor.execute_with_timeout(
fn -> slow_operation() end,
timeout_ms: 5000
)
Summary
Functions
Executes a function directly.
Executes a function asynchronously.
Executes multiple functions in parallel.
Executes a function through a circuit breaker.
Executes with retry and circuit breaker.
Executes a function with retry on transient failures.
Executes a function with a timeout.
Functions
Executes a function directly.
Executes a function asynchronously.
Returns a Task that can be awaited.
Executes multiple functions in parallel.
Returns results in the same order as the input functions.
Options
:timeout_ms- Timeout for all operations (default: 30000):max_concurrency- Maximum concurrent operations (default: unlimited)
@spec execute_with_circuit_breaker(GenServer.server(), (-> any()), keyword()) :: any()
Executes a function through a circuit breaker.
@spec execute_with_protection(GenServer.server(), (-> any()), keyword()) :: any()
Executes with retry and circuit breaker.
Combines retry logic with circuit breaker protection.
Executes a function with retry on transient failures.
Options
:max_attempts- Maximum attempts (default: 3):backoff_ms- List of backoff delays (default: [100, 200, 400]):retriable_errors- Errors to retry (default: [:timeout, :unavailable]):jitter- Add random jitter (default: false)
Executes a function with a timeout.
Returns {:error, :timeout} if the function doesn't complete in time.
Options
:timeout_ms- Timeout in milliseconds (required)