Execution helpers with retry, circuit breaker, and timeout support.
Legacy Optional Module
Snakepit does not call this module internally. It remains available for
compatibility and may be removed in v0.16.0 or later.
Prefer explicit use of Snakepit.RetryPolicy, Snakepit.CircuitBreaker,
and the internal TimeoutRunner module in new code.
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)