Packages
horde
0.5.0
0.10.0
0.9.1
0.9.0
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.8.0-rc.1
0.7.1
0.7.0
0.6.1
0.6.0
0.6.0-rc.1
0.5.0
0.5.0-rc.12
0.5.0-rc.11
0.5.0-rc.10
0.5.0-rc.9
0.5.0-rc.8
0.5.0-rc.7
0.5.0-rc.6
0.5.0-rc.5
0.5.0-rc.4
0.5.0-rc.3
0.5.0-rc.2
0.5.0-rc.1
0.4.0-rc.2
0.4.0-rc.1
0.3.0
0.3.0-rc1
0.2.3
0.2.2
0.2.1
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Distributed supervisor & process registry built with DELTA-CRDTs
Current section
Files
Jump to
Current section
Files
lib/horde/graceful_shutdown_manager.ex
defmodule Horde.GracefulShutdownManager do
# Horde.GracefulShutdownManager notifies the processes CRDT when a child of the supervisor
# is terminated and the node is shutting down.
#
# This ensures a smooth transition when a node is shutting down. If we did not do this here,
# then we would have to wait until all children of the supervisor were done shutting down
# before releasing them to be restarted on other nodes. If some child processes take much
# longer than others to terminate, then this will result in some child processes being
# unavailable for longer than necessary.
@moduledoc false
use GenServer
require Logger
def child_spec(options) do
%{
id: __MODULE__,
start:
{GenServer, :start_link,
[__MODULE__, Keyword.get(options, :processes_pid), Keyword.take(options, [:name])]}
}
end
def init(processes_pid) do
{:ok, {processes_pid, false}}
end
def handle_call(:horde_shutting_down, _f, {processes_pid, _true_false}) do
{:reply, :ok, {processes_pid, true}}
end
def handle_cast({:shut_down, child_spec}, {processes_pid, true} = s) do
GenServer.cast(
processes_pid,
{:operation, {:add, [{:process, child_spec.id}, {nil, child_spec}]}}
)
{:noreply, s}
end
def handle_cast({:shut_down, _child_id}, s) do
{:noreply, s}
end
end