[erlang-questions] Get grandchild pid when using nested supervisors?
Michael Loftis
mloftis@REDACTED
Mon Sep 29 18:24:07 CEST 2014
On Mon, Sep 29, 2014 at 9:10 AM, Roger Lipscombe <roger@REDACTED> wrote:
> I'm attempting to use nested supervisors, as follows:
>
> Top -> A (simple_one_for_one) --temporary--> B (one_for_one) --transient--> W
>
> The point of this is so that, if W crashes, it gets restarted
> according to B's strategy, but that -- if the restart intensity is
> reached, A is _not_ killed (because it's supervising a large number of
> B->W pairs). There's only one W for each B.
>
> So, the first question: is this sane? Or is there a better way to
> implement this?
>
> Assuming it is sane, my second question:
>
> Calling supervisor:start_child(A, []) returns {ok, BPid}, where I
> really want WPid. What's a sensible way to get hold of it?
Typically I would personally have W "call back" to you with it's Pid.
You might have a timeout on wait for the callback. You'd call the
start with additional args so that your pid would get passed through
the supervision tree to the eventual WPid process init(), and either
there in init() have it gen_server:cast or do a usual erlang Pid !
{wpid, self()} or similar.
As for if your supervision tree is normal like that, it doesn't really
matter if it's what you need, right? However, it is normal. It's
actually a lot more normal to have a little bit of a deeper
supervision tree than just a single level, IE, to have one like yours.
Fire up mnesia and connect observer to your node. OR any number of
other applications, you'll see that their supervision trees are 2-3-4
levels deep depending on their needs.
>
> Thanks,
> Roger.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
--
"Genius might be described as a supreme capacity for getting its possessors
into trouble of all kinds."
-- Samuel Butler
More information about the erlang-questions
mailing list