View Source ProcessHub.Service.ProcessRegistry (ProcessHub v0.4.0-beta)
The process registry service provides API functions for managing the process registry.
Summary
Functions
Deletes information about multiple child processes from the registry.
Inserts information about multiple child processes into the registry.
Deletes all objects from the process registry.
Returns a list of child_ids that match the given child_ids variable.
Deletes information about a child process from the registry.
Dumps the whole registry.
Returns the first pid for the given child_id.
Returns a list of pids for the given child_id.
Inserts information about a child process into the registry.
Returns a list of child specs registered under the local node.
Returns information on all processes that are running on the local node.
Return the child_spec, nodes, and pids for the given child_id.
Returns all children that match the given tag.
Returns information about all registered processes. Will be deprecated in the future.
Updates the row on the registry.
Types
@type metadata() :: %{tag: String.t()}
@type registry() :: %{ required(ProcessHub.child_id()) => {ProcessHub.child_spec(), [{node(), pid()}]} }
@type registry_dump() :: %{ required(ProcessHub.child_id()) => {ProcessHub.child_spec(), [{node(), pid()}], metadata()} }
Functions
@spec bulk_delete( ProcessHub.hub_id(), %{ required(ProcessHub.child_id()) => {ProcessHub.child_spec(), [{node(), pid()}]} }, keyword() ) :: :ok
Deletes information about multiple child processes from the registry.
Hook Behavior
This function will dispatch the :registry_pid_remove_hook hook for each child process
if the :hook_storage option is provided. If :hook_storage is nil or not provided,
no hooks will be fired.
Options
:hook_storage- Hook storage to use for dispatching hooks (default:nil)
Parameters
hub_id- The hub identifierchildren- Map of child_id to list of nodes to removeopts- Options keyword list
@spec bulk_insert( ProcessHub.hub_id(), %{ required(ProcessHub.child_id()) => {ProcessHub.child_spec(), [{node(), pid()}], metadata()} }, keyword() ) :: :ok
Inserts information about multiple child processes into the registry.
Hook Behavior
This function will dispatch the :registry_pid_insert_hook hook for each child process
if the :hook_storage option is provided. If :hook_storage is nil or not provided,
no hooks will be fired.
Options
:hook_storage- Hook storage to use for dispatching hooks (default:nil)
Parameters
hub_id- The hub identifierchildren- Map of child_id to {child_spec, node_pids, metadata} tuplesopts- Options keyword list
@spec clear_all(ProcessHub.hub_id()) :: boolean()
Deletes all objects from the process registry.
@spec contains_children(ProcessHub.hub_id(), [ProcessHub.child_id()]) :: [ ProcessHub.child_id() ]
Returns a list of child_ids that match the given child_ids variable.
@spec delete(ProcessHub.hub_id(), ProcessHub.child_id(), keyword() | nil) :: :ok
Deletes information about a child process from the registry.
Hook Behavior
This function will dispatch the :registry_pid_remove_hook hook if the :hook_storage
option is provided. If :hook_storage is nil or not provided, no hooks will be fired.
Options
:hook_storage- Hook storage to use for dispatching hooks (default:nil)
@spec dump(ProcessHub.hub_id()) :: registry_dump()
Dumps the whole registry.
Returns all information about all registered processes including metadata.
@spec get_pid(ProcessHub.hub_id(), ProcessHub.child_id()) :: pid() | nil
Returns the first pid for the given child_id.
@spec get_pids(ProcessHub.hub_id(), ProcessHub.child_id()) :: [pid()]
Returns a list of pids for the given child_id.
@spec insert( ProcessHub.hub_id(), ProcessHub.child_spec(), [{node(), pid()}], keyword() | nil ) :: :ok
Inserts information about a child process into the registry.
Hook Behavior
This function will dispatch the :registry_pid_insert_hook hook if the :hook_storage
option is provided. If :hook_storage is nil or not provided, no hooks will be fired.
Options
:metadata- Additional metadata to store with the process (default:%{}):table- Alternative table to use for storage (default:hub_id):hook_storage- Hook storage to use for dispatching hooks (default:nil)
@spec local_child_specs(ProcessHub.hub_id()) :: [ProcessHub.child_spec()]
Returns a list of child specs registered under the local node.
@spec local_data(ProcessHub.hub_id()) :: [ {ProcessHub.child_id(), {ProcessHub.child_spec(), [{node(), pid()}]}} ]
Returns information on all processes that are running on the local node.
@spec lookup( ProcessHub.hub_id(), ProcessHub.child_id(), keyword() ) :: {ProcessHub.child_spec(), [{node(), pid()}]} | {ProcessHub.child_spec(), [{node(), pid()}], ProcessHub.child_metadata()} | nil
Return the child_spec, nodes, and pids for the given child_id.
@spec match_tag(ProcessHub.hub_id(), String.t()) :: [ {ProcessHub.child_id(), [{node(), pid()}]} ]
Returns all children that match the given tag.
@spec process_list(atom(), :global | :local) :: [ {ProcessHub.child_id(), [{node(), pid()}] | pid()} ]
@spec registry(ProcessHub.hub_id()) :: registry()
Returns information about all registered processes. Will be deprecated in the future.
@spec update(ProcessHub.hub_id(), ProcessHub.child_id(), function()) :: :ok | {:error, String.t()}
Updates the row on the registry.
Hook Behavior
This function intentionally skips hook dispatching during the update operation to avoid duplicate or conflicting hook events. Updates are performed as atomic operations.
Parameters
The update_fn must be a function that accepts 3 parameters containing the existing values:
child_spec- the child specification in map format.node_pids- a keyword list containing a list of node pid pairs. Example:[{:mynode, pid()}]metadata- a map containing the additional information.
The function should return a tuple in the following format: {child_spec, node_pids, metadata}
and those values will be then used to update the row.
Return Values
:ok- On successful update{:error, "No child found"}- If no child is found for the givenchild_id{:error, "Invalid arguments returned from the update function"}- If the update function returns invalid data
Important
Use this function with care as any invalid data may corrupt the registry.