This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Yourapp.YourWorker do | |
use GenServer | |
def start_link(state) do | |
GenServer.start_link(__MODULE__, state) | |
end | |
def init(opts) do | |
initial_state = initialize_worker(opts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change the handling of :begin_handoff | |
# This is triggered whenever a registered process is to be killed. | |
def handle_call({:swarm, :begin_handoff}, _from, current_state) do | |
{:reply, {:resume, produce_outgoing_state(current_state)}, current_state} | |
end | |
# Handle :end_handoff | |
# This is triggered whenever a process has been restarted on a new node. | |
def handle_call({:swarm, :end_handoff, incoming_state}, _from, current_state) do | |
{:noreply, end_handoff_new_state(current_state, incoming_state)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Yourapp.YourSupervisor do | |
use DynamicSupervisor | |
# See https://hexdocs.pm/elixir/Application.html | |
# for more information on OTP Applications | |
def start_link(state) do | |
DynamicSupervisor.start_link(__MODULE__, state, name: __MODULE__) | |
end | |
def init(_) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### In config/config.exs | |
config :libcluster, | |
topologies: [ | |
your_app: [ | |
strategy: Cluster.Strategy.Gossip, | |
config: [ | |
port: 45892, | |
if_addr: "0.0.0.0", | |
multicast_addr: "230.1.1.251", | |
multicast_ttl: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Dockerfile: | |
ENTRYPOINT ["/opt/app/docker-entrypoint-dev.sh"] | |
# In docker-entrypoint-dev.sh: | |
if [ -z ${NODE_IP+x} ]; then | |
export NODE_IP="$(hostname -i | cut -f1 -d' ')" | |
fi | |
elixir --name yourapp@${NODE_IP} --cookie "your_dev_erlang_cookie" -S mix phx.server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### In mix.exs | |
defp deps do | |
[ | |
... | |
{:libcluster, "~> 3.1"}, | |
... | |
] | |
end | |
### In config/prod.exs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Swarm.register_name( | |
:unique_name_for_this_worker_process, | |
Yourapp.YourSupervisor, | |
:register, | |
[Yourapp.YourWorker] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
your_app: &app | |
build: | |
context: ./app | |
ports: | |
- 4000:4000 | |
# ... | |
your_app_2: | |
<<: *app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### In config/config.exs | |
config :libcluster, | |
topologies: [ | |
your_app: [ | |
strategy: Cluster.Strategy.Gossip, | |
config: [ | |
port: 45892, | |
if_addr: "0.0.0.0", | |
multicast_addr: "230.1.1.251", | |
multicast_ttl: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### In mix.exs | |
defp deps do | |
[ | |
... | |
{:libcluster, "~> 3.1"}, | |
... | |
] | |
end | |
### In config/prod.exs |
NewerOlder