Hi,
I’m not able to create and test basic ConsumerSupervisor behavior.
I tried to follow the docs, but had a few issues. First one is that my child spec lacked “restart: :transient” (not present in the docs Printer example https://hexdocs.pm/gen_stage/ConsumerSupervisor.html : should I create an issue ?).
Here’s my code
defmodule BasicConsumerSupervisor do
defmodule MyConsumerSupervisor do
use ConsumerSupervisor
def start_link(arg) do
ConsumerSupervisor.start_link(__MODULE__, arg)
end
def init(_arg) do
children = [%{id: MyConsumer, start: {MyConsumer, :start_link, []}, restart: :transient}]
opts = [strategy: :one_for_one]
ConsumerSupervisor.init(children, opts)
end
end
defmodule MyConsumer do
def start_link(event, truc) do
Task.start_link(fn ->
IO.inspect({self(), event, truc})
end)
end
end
end
And Iex session with errors
iex(2)> {:ok, c} = BasicConsumerSupervisor.MyConsumerSupervisor.start_link([])
{:ok, #PID<0.323.0>}
iex(3)> {:ok, p} = 0..100 |> Enum.to_list |> GenStage.from_enumerable()
{:ok, #PID<0.325.0>}
iex(4)> GenStage.sync_subscribe(c, to: p)
{:ok, #Reference<0.1632678573.1983643649.222301>}
iex(5)>
18:44:26.775 [error] ConsumerSupervisor failed to start child from: {#PID<0.325.0>, #Reference<0.1632678573.1983643649.222301>} with reason: {:undef, [{MyConsumer, :start_link, [0], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}
18:44:26.783 [error] ConsumerSupervisor failed to start child from: {#PID<0.325.0>, #Reference<0.1632678573.1983643649.222301>} with reason: {:undef, [{MyConsumer, :start_link, [1], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}
18:44:26.800 [error] ConsumerSupervisor failed to start child from: {#PID<0.325.0>, #Reference<0.1632678573.1983643649.222301>} with reason: {:undef, [{MyConsumer, :start_link, [2], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}
Any ideas what could be wrong ?
cheers,