Foundation.Infrastructure.PoolWorkers.HttpWorker (foundation v0.1.0)
Sample HTTP connection pool worker for demonstrating connection pooling patterns.
This worker maintains persistent HTTP connections and provides a reusable template for implementing custom pool workers for different resource types.
Usage
# Start pool with HTTP workers
ConnectionManager.start_pool(:http_pool, [
size: 10,
max_overflow: 5,
worker_module: Foundation.Infrastructure.PoolWorkers.HttpWorker,
worker_args: [base_url: "https://api.example.com", timeout: 30_000]
])
# Use pooled connection
ConnectionManager.with_connection(:http_pool, fn worker ->
HttpWorker.get(worker, "/users/123")
end)
Worker Configuration
:base_url
- Base URL for HTTP requests:timeout
- Request timeout in milliseconds:headers
- Default headers for all requests:max_redirects
- Maximum number of redirects to follow
Summary
Functions
Returns a specification to start this module under a supervisor.
Performs a GET request using the pooled worker.
Gets the current status and configuration of the worker.
Performs a POST request using the pooled worker.
Starts an HTTP worker with the given configuration.
Types
@type worker_config() :: [ base_url: String.t(), timeout: timeout(), headers: [{String.t(), String.t()}], max_redirects: non_neg_integer() ]
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Performs a GET request using the pooled worker.
Parameters
worker
- Worker PID from the poolpath
- Request path (relative to base_url)options
- Request options (headers, params, etc.)
Returns
{:ok, response}
- Request successful{:error, reason}
- Request failed
Gets the current status and configuration of the worker.
Parameters
worker
- Worker PID from the pool
Returns
{:ok, status}
- Worker status information
Performs a POST request using the pooled worker.
Parameters
worker
- Worker PID from the poolpath
- Request path (relative to base_url)body
- Request body (will be JSON encoded)options
- Request options (headers, etc.)
Returns
{:ok, response}
- Request successful{:error, reason}
- Request failed
@spec start_link(worker_config()) :: GenServer.on_start()
Starts an HTTP worker with the given configuration.
This function is called by Poolboy to create worker instances.