Nebulex v2.0.0-rc.0 Nebulex.RPC View Source
RPC utilities for distributed task execution.
This module uses supervised tasks underneath Task.Supervisor.
Link to this section Summary
Functions
Evaluates apply(mod, fun, args) on node node and returns the corresponding
evaluation result, or {:badrpc, reason} if the call fails.
In contrast to a regular single-node RPC, a multicall is an RPC that is sent
concurrently from one client to multiple servers. The function evaluates
apply(mod, fun, args) on each node_group entry and collects the answers.
Then, evaluates the reducer function (set in the opts) on each answer.
Similar to multi_call/3 but the same node_callback (given by module,
fun, args) is executed on all nodes; Internally it creates a
node_group with the same node_callback for each node.
Link to this section Types
Specs
Task callback
Specs
Group entry: node -> callback
Specs
node_group() :: %{optional(node()) => callback()} | [node_callback()]
Node group
Specs
Reducer spec
Link to this section Functions
Specs
call(Supervisor.supervisor(), node(), module(), atom(), [term()], timeout()) :: term() | {:badrpc, term()}
Evaluates apply(mod, fun, args) on node node and returns the corresponding
evaluation result, or {:badrpc, reason} if the call fails.
A timeout, in milliseconds or :infinity, can be given with a default value
of 5000. It uses Task.await/2 internally.
Example
iex> Nebulex.RPC.call(:my_task_sup, :node1, Kernel, :to_string, [1])
"1" Specs
multi_call(Supervisor.supervisor(), node_group(), Keyword.t()) :: term()
In contrast to a regular single-node RPC, a multicall is an RPC that is sent
concurrently from one client to multiple servers. The function evaluates
apply(mod, fun, args) on each node_group entry and collects the answers.
Then, evaluates the reducer function (set in the opts) on each answer.
This function is similar to :rpc.multicall/5.
Options
:timeout- A timeout, in milliseconds or:infinity, can be given with a default value of5000. It usesTask.yield_many/2internally.:reducer- Reducer function to be executed on each collected result. (check outreducertype).
Example
iex> Nebulex.RPC.multi_call(
...> :my_task_sup,
...> %{
...> node1: {Kernel, :to_string, [1]},
...> node2: {Kernel, :to_string, [2]}
...> },
...> timeout: 10_000,
...> reducer: {
...> [],
...> fn
...> {:ok, res}, _node_callback, acc ->
...> [res | acc]
...>
...> {:error, _}, _node_callback, acc ->
...> acc
...> end
...> }
...> )
["1", "2"] Specs
Similar to multi_call/3 but the same node_callback (given by module,
fun, args) is executed on all nodes; Internally it creates a
node_group with the same node_callback for each node.
Options
Same options as multi_call/3.
Example
iex> Nebulex.RPC.multi_call(
...> :my_task_sup,
...> [:node1, :node2],
...> Kernel,
...> :to_string,
...> [1],
...> timeout: 5000,
...> reducer: {
...> [],
...> fn
...> {:ok, res}, _node_callback, acc ->
...> [res | acc]
...>
...> {:error, _}, _node_callback, acc ->
...> acc
...> end
...> }
...> )
["1", "1"]