Raxol.Core.ConnectionPool (Raxol v2.0.1)
View SourceGeneric connection pooling implementation for external services.
Provides connection pooling, health checking, and automatic retry capabilities for any external service connections (HTTP, SSH, Database, etc).
Features
- Configurable pool size limits
- Connection health checking
- Automatic reconnection on failure
- Connection timeout management
- Metrics and monitoring
Usage
# Define a pool for an HTTP service
defmodule MyApp.APIPool do
use Raxol.Core.ConnectionPool,alias Raxol.Core.Runtime.Log
name: :api_pool,
pool_size: 10,
max_overflow: 5
end
# Use the pool
ConnectionPool.transaction(:api_pool, fn conn ->
# Use connection
end)
Summary
Functions
Returns a connection to the pool.
Checks out a connection from the pool.
Returns a specification to start this module under a supervisor.
Gets pool statistics.
Executes a function with a connection from the pool.
Types
@type connection() :: term()
@type pool_name() :: atom()
@type pool_opts() :: [ pool_size: pos_integer(), max_overflow: non_neg_integer(), timeout: pos_integer(), idle_timeout: pos_integer(), health_check_interval: pos_integer(), connect_fn: (-> {:ok, connection()} | {:error, term()}), disconnect_fn: (connection() -> :ok), health_check_fn: (connection() -> boolean()) ]
Functions
@spec checkin(pool_name(), connection()) :: :ok
Returns a connection to the pool.
@spec checkout(pool_name(), timeout()) :: {:ok, connection()} | {:error, term()}
Checks out a connection from the pool.
Returns a specification to start this module under a supervisor.
See Supervisor.
Gets pool statistics.
@spec transaction(pool_name(), (connection() -> result), timeout()) :: result when result: term()
Executes a function with a connection from the pool.