Snakepit.Pool.ProcessRegistry (Snakepit v0.6.10)

View Source

Registry for tracking external worker processes with OS-level PID management.

This module maintains a mapping between:

  • Worker IDs
  • Elixir worker PIDs
  • External process PIDs
  • Process fingerprints

Enables robust orphaned process detection and cleanup.

Summary

Functions

Activates a reserved worker with its actual process information.

Returns a specification to start this module under a supervisor.

Cleans up dead worker entries from the registry.

Debug function to show all DETS entries with their BEAM run IDs.

Returns the number of entries currently stored in the DETS table.

Gets all active external process PIDs from registered workers.

Gets all registered external process PIDs, regardless of worker status.

Get the current BEAM run ID.

Gets registry statistics.

Gets information for a specific worker.

Gets workers with specific fingerprints.

Gets all registered worker information.

Manually trigger orphan cleanup. Useful for testing and debugging.

Registers a worker with its external process information. @deprecated Use reserve_worker/1 followed by activate_worker/4 instead

Reserves a worker slot before spawning the process. This ensures we can track the process even if we crash during spawn.

Unregisters a worker from tracking. Returns :ok regardless of whether the worker was registered.

Validates that all registered workers are still alive. Returns a list of dead workers that should be cleaned up.

Checks if a worker is currently registered.

Functions

activate_worker(worker_id, elixir_pid, process_pid, fingerprint)

Activates a reserved worker with its actual process information.

This is a synchronous call that blocks until the worker is registered. This ensures the happens-before relationship: worker registration completes before the worker is considered ready for work.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cleanup_dead_workers()

Cleans up dead worker entries from the registry.

debug_show_all_entries()

Debug function to show all DETS entries with their BEAM run IDs.

dets_table_size()

Returns the number of entries currently stored in the DETS table.

get_active_process_pids()

Gets all active external process PIDs from registered workers.

get_all_process_pids()

Gets all registered external process PIDs, regardless of worker status.

This is useful during shutdown when workers may have been terminated but external processes still need cleanup.

get_beam_run_id()

Get the current BEAM run ID.

get_stats()

Gets registry statistics.

get_worker_info(worker_id)

Gets information for a specific worker.

get_workers_by_fingerprint(fingerprint)

Gets workers with specific fingerprints.

list_all_workers()

Gets all registered worker information.

manual_orphan_cleanup()

Manually trigger orphan cleanup. Useful for testing and debugging.

register_worker(worker_id, elixir_pid, process_pid, fingerprint)

Registers a worker with its external process information. @deprecated Use reserve_worker/1 followed by activate_worker/4 instead

reserve_worker(worker_id)

Reserves a worker slot before spawning the process. This ensures we can track the process even if we crash during spawn.

start_link(opts \\ [])

unregister_worker(worker_id)

Unregisters a worker from tracking. Returns :ok regardless of whether the worker was registered.

validate_workers()

Validates that all registered workers are still alive. Returns a list of dead workers that should be cleaned up.

worker_registered?(worker_id)

Checks if a worker is currently registered.