Snakepit.Pool.Registry (snakepit v0.1.2)

Registry 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

Summary

Functions

Returns the child spec for the registry.

Get worker_id from PID for O(1) lookups in :DOWN messages.

Gets the PID for a worker ID.

Lists all registered worker IDs.

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

child_spec(opts)

Returns the child spec for the registry.

get_worker_id_by_pid(pid)

Get worker_id from PID for O(1) lookups in :DOWN messages.

get_worker_pid(worker_id)

Gets the PID for a worker ID.

list_workers()

Lists all registered worker IDs.

register_worker(worker_id, pid)

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.

via_tuple(worker_id)

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"}}

worker_count()

Counts the number of registered workers.

worker_exists?(worker_id)

Checks if a worker is registered.