View Source ProcessHub.Service.Distributor (ProcessHub v0.5.0-beta)
The distributor service provides API functions for distributing child processes.
Summary
Functions
Calculates the GenServer.call timeout based on child count.
Terminates child processes locally and propagates all nodes in the cluster to remove the child processes from their registry.
Composes and dispatches a start children operation.
Composes and dispatches a stop children operation.
Applies default initialization options to the provided options keyword list.
Return a list of all child processes started by all nodes in the cluster.
Returns all child processes started by the local node.
Functions
@spec calculate_call_timeout( non_neg_integer(), keyword() ) :: timeout()
Calculates the GenServer.call timeout based on child count.
The timeout is calculated as @base_call_timeout + (child_count * @timeout_per_child),
which equals 5000ms + (1ms × child_count).
Allows user override via :call_timeout option.
Examples
iex> ProcessHub.Service.Distributor.calculate_call_timeout(100, [])
5100
iex> ProcessHub.Service.Distributor.calculate_call_timeout(10000, [])
15000
iex> ProcessHub.Service.Distributor.calculate_call_timeout(30000, [])
35000
iex> ProcessHub.Service.Distributor.calculate_call_timeout(100, call_timeout: :infinity)
:infinity
iex> ProcessHub.Service.Distributor.calculate_call_timeout(100, call_timeout: 60000)
60000
@spec children_terminate( ProcessHub.Hub.t(), [ProcessHub.child_id()], ProcessHub.Strategy.Synchronization.Base ) :: [{ProcessHub.child_id(), term(), node()}]
Terminates child processes locally and propagates all nodes in the cluster to remove the child processes from their registry.
@spec compose_start_operation( ProcessHub.Hub.t(), [ProcessHub.child_spec()], keyword() ) :: {:ok, ProcessHub.Service.RequestManager.t()} | {:error, :no_children | {:already_started, [ProcessHub.child_id()]} | any()}
Composes and dispatches a start children operation.
@spec compose_stop_operation(ProcessHub.Hub.t(), [ProcessHub.child_id()], keyword()) :: {:ok, ProcessHub.Service.RequestManager.t()} | {:error, :no_children}
Composes and dispatches a stop children operation.
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-10000ms (10.0 seconds) - Maximum time to wait for process initialization:awaitable-false- Whether to return an awaitableProcessHub.Future.t()struct:async_wait-false- Deprecated - Use:awaitableinstead:check_existing-true- Whether to check if processes already exist before starting:on_failure-:continue- Action on failure (:continueor:rollback):metadata-%{}- Additional metadata to attach to processes:await_timeout-60000ms (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: []
]
@spec which_children_global( ProcessHub.Hub.t(), keyword() ) :: list()
Return a list of all child processes started by all nodes in the cluster.
@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.