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
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Other popular topics
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
I would like to know what is the best IDE for elixir development?
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









