1
votes

I am trying to input the number of nodes and start genserver processes for each of the nodes; that is each GenServer.start_link(n) (where n is node number) starts a separate process (PID) for each process.

pids = Enum.map(1..totalnodes, fn n ->
  {:ok, unit} = GenSerModule.start_link(n)
  unit
end)

The pids are returned from this line (#<12.2.2.1>, #<12.2.2.2>, and so on).

Now I want to start the nodes under a Supervisor. That is I must start the genserver processes through the Supervisor's init function for each node and get the PIDs. Something like this: (I know it is wrong)

pids = Enum.map(1..totalNodes, fn n ->
  {:ok, unit} = worker(GenServerModule, n)
  unit
end)
Supervisor.init(nodeMap,[strategy: :one_for_one])

I want to get the PIDs of started child processes in this function where I start the child processes through the Supervisor. I am stuck here.

How do I do this?

1

1 Answers

1
votes

Supervisor.Spec.worker/3, besides that it’s deprecated, does not do any action, it returns a childspec tuple.

When one needs to dynamically start workers, supervised, they usually use DynamicSupervisor.

But if by nodes you mean remote nodes, it’s impossible to supervise remote processes because (besides many other issues) it violates fault tolerance (the VM cannot ensure another VM is ever up.)