Packages

A distributed service registry built on top of phoenix_pubsub. Requests are dispatched to one or more services based on hashed keys.

Current section

Files

Jump to
dispatch lib dispatch supervisor.ex
Raw

lib/dispatch/supervisor.ex

defmodule Dispatch.Supervisor do
use Supervisor
def start_link(_opts \\ []) do
Supervisor.start_link(__MODULE__, :ok, name: __MODULE__)
end
def init(:ok) do
pubsub = Application.get_env(:dispatch, :pubsub, [])
opts = pubsub[:opts] || []
opts = Keyword.put_new(opts, :name, Dispatch.PubSub)
registry =
Application.get_env(:dispatch, :registry, [])
|> Keyword.put_new(:name, Dispatch.Registry)
|> Keyword.put_new(:dispatch_name, Keyword.fetch!(opts, :name))
children = [
{Phoenix.PubSub.Supervisor, opts},
{Dispatch.Registry, registry},
{Dispatch.HashRingServer, registry},
{Task.Supervisor, [name: Dispatch.TaskSupervisor]}
]
Supervisor.init(children, strategy: :rest_for_one)
end
end