defmodule Retort do @moduledoc """ Supervise RabbitMQ connection, so it can be reconnected """ import Supervisor.Spec use Application # Functions ## Application callbacks # See http://elixir-lang.org/docs/stable/elixir/Application.html # for more information on OTP Applications @spec start(any, any) :: {:ok, pid} def start(_type, _args) do import Supervisor.Spec, warn: false children = [ worker(Retort.Connection, [nil, [name: Retort.Connection]]) | repo_children() ] # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: Retort] Supervisor.start_link(children, opts) end ## Private Functions defp repo_children do :retort |> Application.get_env(:ecto_repos, []) |> Enum.map(&repo_worker/1) end defp repo_worker(repo), do: worker(repo, []) end