Packages
cloister
0.6.3
0.18.1
0.18.0
0.17.3
0.17.2
0.17.1
0.17.0
0.16.0
0.15.0
0.14.0
0.13.0
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.9.0
0.8.0
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.5
0.6.4
0.6.3
retired
0.6.2
retired
0.6.1
retired
0.6.0
retired
0.5.0
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.2
0.2.1
0.2.0
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
The helper application to manage cluster, that uses hash ring to route requests to nodes. Automatically keeps track of connected nodes, provides helpers to determine where the term is to be executed, to multicast to all the nodes in the cluster and to retrieve current state of the cluster.
Retired package: Release invalid - Use version 0.6.4 instead
Current section
Files
Jump to
Current section
Files
lib/cloister/manager.ex
defmodule Cloister.Manager do
@moduledoc """
Use this module to start _Cloister_ manually inside the application
supervision tree instead of running it as an application (default.)
This is not recommended and requires better understanding of internals.
Also, `:cloister` must be put into `:included_applications` section
of your application `mix.exs` to prevent the application from starting up
during the dependent applications starting phase.
"""
use Supervisor
@doc "Starts the cloister manager process in the supervision tree"
@spec start_link(opts :: keyword()) :: GenServer.on_start()
def start_link(opts) do
:ok = Application.ensure_started(:libring, :permanent)
{state, opts} = Keyword.pop(opts, :state, [])
Supervisor.start_link(__MODULE__, state, Keyword.put_new(opts, :name, __MODULE__))
end
@doc false
@impl Supervisor
def init(state) do
state = Keyword.put_new(state, :otp_app, Application.get_env(:cloister, :otp_app, :cloister))
{monitor_opts, state} = Keyword.pop(state, :monitor_opts, [])
{additional_modules, state} =
Keyword.pop(
state,
:additional_modules,
Application.get_env(:cloister, :additional_modules, [])
)
additional_modules = Enum.filter(additional_modules, &ensure_compiled?/1)
children =
[
{Cloister.Monitor, [{:state, state} | monitor_opts]},
Cloister,
Cloister.Node
] ++ additional_modules
Supervisor.init(children, strategy: :rest_for_one)
end
@spec ensure_compiled?(module()) :: boolean()
defp ensure_compiled?(module),
do: match?({:module, ^module}, Code.ensure_compiled(module))
end