voger
Supervisor child_spec wraps list with list
Hello, I am trying to refresh my GenServer, Supervisor knowledge and I am trying to convert pooly from “The Little Elixir & OTP Guidebook” to newer Supervisor and child_spec forms.
So we have a main Supervisor module that on initialization it runs a GenServer
defmodule Pooly.Supervisor do
use Supervisor
require Cl
def init(pool_config) do
children =
[
# Here I am trying to pass two arguments to Pooly.Server.start_link/2
{Pooly.Server, [self(), pool_config]}
]
|> Cl.inspect(label: "-cb The children")
opts = [strategy: :one_for_all]
Supervisor.init(children, opts)
|> Cl.inspect(label: "-cb After init")
end
end
defmodule Pooly.Server do
use GenServer
def start_link(supervisor, pool_config) do
GenServer.start_link(__MODULE__, [supervisor, pool_config], name: __MODULE__)
end
# ...
end
Unfortunately when I try to run this I get
```console
$ iex -S mix
Erlang/OTP 22 [erts-10.7.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Compiling 1 file (.ex)
lib/pooly/supervisor.ex
Pooly.Supervisor:15
The children: [
{Pooly.Server,
[#PID<0.198.0>, [mfa: {SampleWorker, :start_link, []}, size: 5]]}
]
-----------------------------------------------------------------------------------------------
lib/pooly/supervisor.ex
Pooly.Supervisor:20
After init: {:ok,
{%{intensity: 3, period: 5, strategy: :one_for_all},
[
%{
id: Pooly.Server,
start: {Pooly.Server, :start_link,
[[#PID<0.198.0>, [mfa: {SampleWorker, :start_link, []}, size: 5]]]}
}
]}}
-----------------------------------------------------------------------------------------------
** (Mix) Could not start application pooly: Pooly.start(:normal, []) returned an error: shutdown: failed to start child: Pooly.Server
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Pooly.Server.start_link/1 is undefined or private
(pooly 0.1.0) Pooly.Server.start_link([#PID<0.198.0>, [mfa: {SampleWorker, :start_link, []}, size: 5]])
(stdlib 3.12.1) supervisor.erl:379: :supervisor.do_start_child_i/3
(stdlib 3.12.1) supervisor.erl:365: :supervisor.do_start_child/2
(stdlib 3.12.1) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2
(stdlib 3.12.1) supervisor.erl:1157: :supervisor.children_map/4
(stdlib 3.12.1) supervisor.erl:315: :supervisor.init_children/2
(stdlib 3.12.1) gen_server.erl:374: :gen_server.init_it/2
(stdlib 3.12.1) gen_server.erl:342: :gen_server.init_it/6
So, when the children list is defined, the child spec has the arguments in a nice list.
[#PID<0.198.0>, [mfa: {SampleWorker, :start_link, []}, size: 5]]}
But after Supervisor.init(children, opts) that list becomes item of a list
[[#PID<0.198.0>, [mfa: {SampleWorker, :start_link, []}, size: 5]]]}
and I believe init tries to call Pooly.Server.start_link/2 with that item as the only argument and offcourse it fails.
How can I fix that?
Marked As Solved
LostKobrakai
The new child_spec system normalized to only support ˋstart_link/1ˋ, unless you explicitly create a custom ˋchild_spec/1ˋ callback on the started module.
1
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
can someone please explain to me how Enum.reduce works with maps
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Other popular topics
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New







