I have an Erlang app where I have a simple_one_for_one
supervisor that supervises a set of processes that watch for changes on web pages (one URL per child).
I start the children that should be active in my application behaviour's start
function, after having added the supervisor in question to the app's top supervisor (along with some other processes). Children are then started and stopped dynamically as entries are added/removed (and the entries are persisted to a DB).
If this simple_one_for_one
supervisor crashes because too many of its children crash (eg due to a network issue), the supervisor itself is restarted, but its children are lost. At this point I want to check the DB and start the children that should be active again.
But, how should I restart the children? How can I tell that the supervisor restarted? Should I schedule starting the children from the supervisor's own start_link
function? Is there a better way to design this?
simple_one_for_one
supervisor to#{strategy => simple_one_for_one,
intensity => 0,
period => 1}
terminate/2
method toterminate(normal, _State) ->
%% process terminated normally
ok;
terminate(_Reason, _State) ->
%% spawn the child again
do_supverisor_start_child(),
ok.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.