Erlang supervisor with one critical child
We are in the process of re-organizing our applications supervision tree to make it more robustly handle failures and re-starts. However, we have a scenario where we have one parent supervisor that starts four child supervisors. The problem we have is that the first child supervisor starts several children gen_servers that must be started and initialized prior to the second child supervisor starting or it will fail.
So, I need a startup like the following:
test_app.erl -> super_supervisor -> [config_supervisor, auth_supervisor, rest_supervisor]
The trick I'm having trouble with is that config_supervisor must complete all initialization prior to auth_supervisor or rest_supervisor being started. With the rest_for_one startup strategy I get, essentially, this behavior but only by allowing auth_supervisor to fail because the needed config is not there. I would prefer to just request that config_supervisor is completed with it's initialization (which includes starting several gen_servers) prior to moving-on to auth_supervisor.
This seems like a common scenario that would have been conquered previously but, I am having a hard time "googling" a solution. Does anybody have advice or sample code that might exist to handle this scenario?
Supervisors do a synchronous start of their children, starting each one in turn before starting the next in the order they occur in the childspeclist . So your super_supervisor
should start its children in the right order, first config_supervisor
, then auth_supervisor
and finally rest_supervisor
by having them in that order. A supervisor must (successfully) start all its children before it is considered to be started. So if config_supervisor
has all the necessary processes which must be started during the initialization as its children then super_supervisor
will not start the other supervisors until the config_supervisor
is done.
In this case you would not need rest_for_one
to ensure starting in the right order if the children are in the right order in the childspeclist.
For a worker process, gen_server/gen_fsm/gen_event, they are considered started when their init
callback returns.
Have I understood your description and question correctly?
您可以尝试将config_supervisor移动到其自己的应用程序中,并将该应用程序设置为主应用程序的一个需求,在这种情况下,配置应用程序将首先启动,然后具有auth_supervisor的主管理器等将开始其初始化。
Did you look at the rest_for_one restart strategy? It seems that it should be covenient in this case, the middle supervisor starts the gen_servers in a defined order and last the leaf supervisor who in turn start the critical process.
链接地址: http://www.djcxy.com/p/38214.html上一篇: 如何引用Elixir主管中以前启动的流程
下一篇: Erlang的主管与一个关键的孩子