Snakepit.Pool.Registry (Snakepit v0.6.10)
View SourceRegistry for pool worker processes.
This is a thin wrapper around Elixir's Registry that provides:
- Consistent naming for worker processes
- Easy migration path to distributed registry (Horde)
- Helper functions for worker lookup
Canonical Metadata
All workers store a metadata map containing the following canonical keys:
:worker_module– module that owns the worker implementation (usuallySnakepit.GRPCWorker):pool_name– atom name of the logical pool (e.g.:default):pool_identifier– optional human-friendly identifier used in docs/metrics:adapter_module– adapter used to launch the Python worker
Higher-level helpers (pool, diagnostics, worker profiles) should prefer
Snakepit.Pool.Registry.fetch_worker/1 so these keys stay authoritative.
Summary
Functions
Returns the child spec for the registry.
Returns {pid, metadata} for a registered worker.
Get worker_id from PID for O(1) lookups in :DOWN messages.
Returns only the metadata for a worker.
Gets the PID for a worker ID.
Lists all registered worker IDs.
Returns the list of canonical metadata keys maintained for each worker.
Adds or updates metadata for a registered worker.
Register a worker with metadata for O(1) reverse lookups. This is only used for manual registration - workers started with via_tuple are already registered.
Returns a via tuple for registering/looking up a worker process.
Counts the number of registered workers.
Checks if a worker is registered.
Functions
Returns the child spec for the registry.
Returns {pid, metadata} for a registered worker.
Get worker_id from PID for O(1) lookups in :DOWN messages.
Returns only the metadata for a worker.
Gets the PID for a worker ID.
Lists all registered worker IDs.
Returns the list of canonical metadata keys maintained for each worker.
Adds or updates metadata for a registered worker.
Accepts maps to keep metadata consistent across callers. When Registry
has nil metadata (the default when using :via tuples), this function
replaces it with the provided map. Future updates merge with the existing map.
Returns :ok on success or {:error, :not_registered} if the worker has
not been registered yet (best-effort semantics).
Register a worker with metadata for O(1) reverse lookups. This is only used for manual registration - workers started with via_tuple are already registered.
Returns a via tuple for registering/looking up a worker process.
Examples
iex> Snakepit.Pool.Registry.via_tuple("worker_123")
{:via, Registry, {Snakepit.Pool.Registry, "worker_123"}}
Counts the number of registered workers.
Checks if a worker is registered.