voger

voger

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?

Showing Posts 1 to 1

LostKobrakai

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews