Fly.RPC (Fly RPC v0.2.0) View Source
Provides an RPC interface for executing an MFA on a node within a region.
Configuration
Assumes each node is running the Fly.RPC
server in its supervision tree and
exports FLY_REGION
environment variable to identify the fly region.
To run code on a specific region call rpc_region/4
. A node found within the
given region will be chosen at random. Raises if no nodes exist on the given
region.
The special :primary
region may be passed to run the rpc against the region
identified by the PRIMARY_REGION
environment variable.
Examples
> rpc_region("hkg", String, :upcase, ["fly"])
"FLY"
> rpc_region(Fly.primary_region(), String, :upcase, ["fly"])
"FLY"
> rpc_region(:primary, String, :upcase, ["fly"])
"FLY"
Server
The GenServer's responsibility is just to monitor other nodes as they enter and leave the cluster. It maintains a list of nodes and the Fly.io region where they are deployed in an ETS table that other processes can use to find and initiate their own RPC calls to.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Callback implementation for GenServer.handle_continue/2
.
Callback implementation for GenServer.init/1
.
Executes a function on the remote node to determine if the RPC API support is available.
Asks a node what Fly region it's running in.
Returns the Elixir OTP nodes registered the region. Reads from a local cache.
Executes the function on the remote node and waits for the response.
Executes the MFA on an available node in the desired region.
Link to this section Types
Specs
region() :: String.t() | :primary
Specs
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Callback implementation for GenServer.handle_continue/2
.
Callback implementation for GenServer.init/1
.
Specs
Executes a function on the remote node to determine if the RPC API support is available.
Support may not exist on the remote node in a "first roll out" scenario.
Specs
Asks a node what Fly region it's running in.
Returns :error
if RPC is not supported on remote node.
Returns the Elixir OTP nodes registered the region. Reads from a local cache.
Specs
Executes the function on the remote node and waits for the response.
Exits after timeout
milliseconds.
Specs
Executes the MFA on an available node in the desired region.
If the region is the "primary" region or the "local" region then execute the
function immediately. Supports the string name of the region or :primary
for
the current configured primary region.
Otherwise find an available node and select one at random to execute the function.
Raises ArgumentError
when no available nodes.
Example
> RPC.rpc_region("hkg", Kernel, :+, [1, 2])
3
> RPC.rpc_region(:primary, Kernel, :+, [1, 2])
3