How to implement Supervisors of Supervisors?

I simply want to build a Supervision tree like in this picture:

But I can’t find any information on how doing so. What I did so far:
In appplication.ex

defmodule MyApp.Application do
    use Application
    def start(_type, _args) do
        children = [{MyApp.Supervisor, [:hello]}]
        opts = [strategy: :one_for_one]
        Supervisor.start_link(children, opts)

In supervisor.ex

defmodule MyApp.Supervisor do
    use Supervisor
    def start_link(args) do
        children = [{MyApp.Worker, [:world]}]
        opts = [strategy: :one_for_one]
        Supervisor.start_link(children, opts)

The Worker is a typical :pop :push Stacklike implementation.
When I try to run it, I get the following error:

** (ArgumentError) The module MyApp.Supervisor was given as a 
child to a supervisor but it does not impement child_spec/1

So I tried to implement the child_spec function, though in the Supervisor doc it is written, that the use Supervisor will do that for me.

I honestly don’t know how to build such a simple supervision tree. I have the PragProg book “Programming Elixir” which handles exactly this situation, but it is written for Elixir 1.3 and I want to implement it with 1.5. The Supervisor.Spec documentation tells me that it is deprecated, but that is the only way I find on the internet, where such a simple Supervision tree is built (with the supervise() function.

Am I misunderstanding basic idioms here? Are you supposed not to implement such a structure with maybe even more levels of Supervisors?

thanks in advance so far.

Are you not missing the init/1 callback?


defmodule KV.Supervisor do
  use Supervisor

  def start_link(opts) do
    Supervisor.start_link(__MODULE__, :ok, opts)

  def init(:ok) do
    children = [

    Supervisor.init(children, strategy: :one_for_one)
1 Like

Okay, I got it now. Thanks @orestis!

I thought I already tried that, because I did read that article already a couple of times. Might have messed up something.