adding kill button
This commit is contained in:
@@ -9,6 +9,15 @@ defmodule Backend.Cluster do
|
||||
def start_link(opts) do
|
||||
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
|
||||
end
|
||||
|
||||
def kill_node(node_name) when is_binary(node_name) do
|
||||
kill_node(String.to_existing_atom(node_name))
|
||||
end
|
||||
|
||||
def kill_node(target) when is_atom(target) do
|
||||
Logger.warning("Killing node: #{target}")
|
||||
:rpc.cast(target, :init, :stop, [])
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(_opts) do
|
||||
@@ -62,4 +71,5 @@ defmodule Backend.Cluster do
|
||||
# Retry connection every 10 seconds
|
||||
Process.send_after(self(), :periodic_connect, 10_000)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -52,7 +52,6 @@ defmodule Backend.GlobalSingleton do
|
||||
|
||||
@impl true
|
||||
def handle_info({:startup_args_updated, new_args}, state) do
|
||||
Logger.info("Received updated startup args for #{state.module}: #{inspect(new_args)}")
|
||||
{:noreply, %{state | startup_args: new_args}}
|
||||
end
|
||||
|
||||
|
||||
@@ -6,11 +6,25 @@ defmodule BackendWeb.ClusterStatusChannel do
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def join("clusterstatus", _params, socket) do
|
||||
def join("cluster_status", _params, socket) do
|
||||
Logger.info("Client joined clusterstatus channel")
|
||||
{:ok, %{status: "connected"}, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_in("get_nodes", _payload, socket) do
|
||||
Logger.info("Client requested node list #{inspect(Node.list())}")
|
||||
push(socket, "node_list", %{other_nodes: Node.list(), connected_node: node()})
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_in("kill_node", %{"node" => node_to_kill}, socket) do
|
||||
Logger.warning("Client requested to kill node: #{node_to_kill}")
|
||||
Backend.Cluster.kill_node(node_to_kill)
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_in(_event, _payload, socket) do
|
||||
{:noreply, socket}
|
||||
|
||||
@@ -47,6 +47,8 @@ defmodule BackendWeb.ConnectedUserChannel do
|
||||
end
|
||||
|
||||
@impl true
|
||||
@spec handle_in(<<_::48, _::_*8>>, map(), any()) ::
|
||||
{:noreply, any()} | {:reply, :ok, Phoenix.Socket.t()}
|
||||
def handle_in("join_game", %{"name" => name}, socket) do
|
||||
Logger.info("Player '#{name}' joining game on #{node()}")
|
||||
|
||||
|
||||
@@ -2,10 +2,9 @@ defmodule BackendWeb.UserSocket do
|
||||
use Phoenix.Socket
|
||||
require Logger
|
||||
|
||||
|
||||
## Channels
|
||||
channel("user:*", BackendWeb.ConnectedUserChannel)
|
||||
channel("clusterstatus", BackendWeb.ClusterStatusChannel)
|
||||
channel("cluster_status", BackendWeb.ClusterStatusChannel)
|
||||
|
||||
@impl true
|
||||
def connect(%{"user_name" => user_name}, socket, _connect_info) do
|
||||
|
||||
Reference in New Issue
Block a user