I’m having trouble getting Supervisor.start_child to work and I get the following error when running these commands (the supervisor is started automatically. Any help is appreciated. I’m likely missing something simple.
import Supervisor.Spec
sup_pid = sup_pid = Process.whereis(App.SessionSupervisor)
Supervisor.start_child(sup_pid,["a"])
{:error,
{:EXIT,
{:undef,
[{App.Session, :start_link, [["a"]], []},
{:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 374]},
{:supervisor, :handle_call, 3, [file: 'supervisor.erl', line: 399]},
{:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 629]},
{:gen_server, :handle_msg, 5, [file: 'gen_server.erl', line: 661]},
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}}
session_supervisor.ex
defmodule App.SessionSupervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok, name: App.SessionSupervisor)
end
def init(:ok) do
children = [worker(App.Session, [], restart: :transient)]
worker(App.Session, [], restart: :transient)
supervise(children, strategy: :simple_one_for_one)
end
end
session.ex
defmodule App.Session do
use GenServer
@doc """
Starts a new session.
"""
def start_link(uuid, opts \\ []) do
GenServer.start_link(__MODULE__, %{uuid: uuid})
end
… rest of the code.