View Source ProcessHub.Service.Distributor (ProcessHub v0.4.1-beta)

The distributor service provides API functions for distributing child processes.

Summary

Functions

Terminates child processes locally and propagates all nodes in the cluster to remove the child processes from their registry.

Applies default initialization options to the provided options keyword list.

Initiates processes startup.

Initiates processes shutdown.

Return a list of all child processes started by all nodes in the cluster.

Returns all child processes started by the local node.

Functions

Link to this function

children_redist_init(hub, node, children_data, opts \\ [])

View Source
@spec children_redist_init(
  ProcessHub.Hub.t(),
  node(),
  [{ProcessHub.child_spec(), ProcessHub.child_metadata()}],
  keyword() | nil
) :: {:ok, :redistribution_initiated} | {:ok, :no_children_to_redistribute}

Initiates process redistribution.

Link to this function

children_terminate(hub, child_ids, sync_strategy, stop_opts \\ [])

View Source
@spec children_terminate(
  ProcessHub.Hub.t(),
  [ProcessHub.child_id()],
  ProcessHub.Strategy.Synchronization.Base,
  keyword()
) :: [ProcessHub.Handler.ChildrenRem.StopHandle.t()]

Terminates child processes locally and propagates all nodes in the cluster to remove the child processes from their registry.

@spec default_init_opts(keyword()) :: keyword()

Applies default initialization options to the provided options keyword list.

This function takes a keyword list of options and merges it with sensible default values for process initialization operations. Only missing keys are added; existing values in the input options are preserved.

Parameters

  • opts - A keyword list of initialization options

Default Values Applied

  • :timeout - 10000 ms (10.0 seconds) - Maximum time to wait for process initialization
  • :awaitable - false - Whether to return an awaitable ProcessHub.Future.t() struct
  • :async_wait - false - Deprecated - Use :awaitable instead
  • :check_existing - true - Whether to check if processes already exist before starting
  • :on_failure - :continue - Action on failure (:continue or :rollback)
  • :metadata - %{} - Additional metadata to attach to processes
  • :await_timeout - 60000 ms (60 seconds) - Maximum lifetime for collector processes
  • :init_cids - [] - List of child IDs expected to be initialized

Examples

iex> ProcessHub.Service.Distributor.default_init_opts([timeout: 5000, awaitable: true])
[
  timeout: 5000,
  awaitable: true,
  async_wait: false,
  check_existing: true,
  on_failure: :continue,
  metadata: %{},
  await_timeout: 60000,
  init_cids: []
]
Link to this function

init_children(hub, child_specs, opts)

View Source
@spec init_children(ProcessHub.Hub.t(), [ProcessHub.child_spec()], keyword()) ::
  {:ok, :start_initiated}
  | (-> {:ok, list()})
  | {:error,
     :child_start_timeout
     | :no_children
     | {:already_started, [ProcessHub.child_id()]}
     | any()}

Initiates processes startup.

Link to this function

stop_children(hub, child_ids, opts)

View Source
@spec stop_children(ProcessHub.Hub.t(), [ProcessHub.child_id()], keyword()) ::
  (-> {:error, list()} | {:ok, list()}) | {:ok, :stop_initiated}

Initiates processes shutdown.

Link to this function

which_children_global(hub, opts)

View Source
@spec which_children_global(
  ProcessHub.Hub.t(),
  keyword()
) :: list()

Return a list of all child processes started by all nodes in the cluster.

Link to this function

which_children_local(hub, opts)

View Source
@spec which_children_local(ProcessHub.Hub.t(), keyword() | nil) ::
  {node(),
   [
     {any(), :restarting | :undefined | pid(), :supervisor | :worker,
      :dynamic | list()}
   ]}

Returns all child processes started by the local node.

Works similar to Supervisor.which_children/1 but returns a list of tuple where the first element is the node name and the second child processes started under the node.