Current section
Files
Jump to
Current section
Files
lib/strategy/epmd.ex
defmodule Cluster.Strategy.Epmd do
@moduledoc """
This clustering strategy relies on Erlang's built-in distribution protocol.
You can have libcluster automatically connect nodes on startup for you by configuring
the strategy like below:
config :libcluster,
topologies: [
epmd_example: [
strategy: #{__MODULE__},
config: [
hosts: [:"a@127.0.0.1", :"b@127.0.0.1"]]]]
"""
use Cluster.Strategy
def child_spec(opts) do
%{
id: __MODULE__,
start: {__MODULE__, :start_link, [opts]},
type: :worker,
restart: :permanent,
shutdown: 500
}
end
def start_link(opts) do
topology = Keyword.fetch!(opts, :topology)
config = Keyword.get(opts, :config, [])
connect = Keyword.fetch!(opts, :connect)
list_nodes = Keyword.fetch!(opts, :list_nodes)
case Keyword.get(config, :hosts, []) do
[] ->
:ignore
nodes when is_list(nodes) ->
Cluster.Strategy.connect_nodes(topology, connect, list_nodes, nodes)
:ignore
end
end
end