Raxol.Core.ConnectionPool (Raxol v2.0.1)

View Source

Generic 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

connection()

@type connection() :: term()

pool_name()

@type pool_name() :: atom()

pool_opts()

@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

checkin(pool_name, conn)

@spec checkin(pool_name(), connection()) :: :ok

Returns a connection to the pool.

checkout(pool_name, timeout \\ 5000)

@spec checkout(pool_name(), timeout()) :: {:ok, connection()} | {:error, term()}

Checks out a connection from the pool.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(init_opts \\ [])

stats(pool_name)

@spec stats(pool_name()) :: map()

Gets pool statistics.

transaction(pool_name, fun, timeout \\ 5000)

@spec transaction(pool_name(), (connection() -> result), timeout()) :: result
when result: term()

Executes a function with a connection from the pool.