1
votes

the problem is that when in Supervisor you try this:

children = [
  {
    DynamicSupervisor,
    name: SomeName,
    strategy: :one_for_one
  },
  {
    DynamicSupervisor,
    name: AnotherName,
    strategy: :one_for_one
  }
]

You end up receiving this:

** (Mix) Could not start application eap:

PocAbilityProvider.start(:normal, []) returned an error: bad child specification, more than one child specification has the id: DynamicSupervisor. If using maps as child specifications, make sure the :id keys are unique. If using a module or {module, arg} as child, use Supervisor.child_spec/2 to change the :id, for example:

children = [ Supervisor.child_spec({MyWorker, arg}, id: :my_worker_1), Supervisor.child_spec({MyWorker, arg}, id: :my_worker_2) ]

I tried to pull off something like

OPTION1

children = [
  {
    DynamicSupervisor,
    name: SomeName,
    strategy: :one_for_one,
    id: :unique_id
  },
  {
    DynamicSupervisor,
    name: AnotherName,
    strategy: :one_for_one,
    id: :even_more_unique_id
  }
]

OPTION2

children = [
  {
    DynamicSupervisor,
    [
      [
        name: SomeName,
        strategy: :one_for_one
      ],
      id: :unique_id
    ]
  },
  {
    DynamicSupervisor,
    [
      [
        name: AnotherName,
        strategy: :one_for_one
      ],
      id: :even_more_unique_id
    ]
  }
]

But it still returns same error. Is it possible to start two DynamicSupervisors under one supervisor?

2

2 Answers

2
votes

DynamicSupervisor.child_spec/1 implicitly defines :id as the module name, DynamicSupervisor. To overcome this, one might either use module-based supervisors for both, with different modules (it won’t be DRY if the behaviour should be exactly same,) or use am explicit Supervisor.child_spec/2 as:

children = [
  Supervisor.child_spec(
    {DynamicSupervisor, []},
    id: :id1, name: :name1, strategy: :one_for_one),
  Supervisor.child_spec(
    {DynamicSupervisor, []},
    id: :id2, name: :name2, strategy: :one_for_one)
]

This wrapper would overwrite the default id.

0
votes
children = [
  Supervisor.child_spec(
    {DynamicSupervisor, name: SomeName, strategy: :one_for_one}, 
     id: :dyn_sup_1), 
  Supervisor.child_spec(
    {DynamicSupervisor, name: AnotherName, strategy: :one_for_one}, 
     id: : dyn_sup_2)]

This is it the correct order to start two or more DynamicSupervisors