1
votes

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 (e.g. 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?

1
Shouldn't you have a supervisor above this which manages it?Callam Delaney
@CallamDelaney Not sure what you mean. If I have a supervisor above the simple_one_for_one supervisor (I already do – a one_for_one supervisor that also supervises some other things), how should that supervisor know when to restart the simple_one_for_one supervisor's children?beta

1 Answers

0
votes
  1. Change the restart strategy of the simple_one_for_one supervisor to
#{strategy => simple_one_for_one,
                 intensity => 0,
                 period => 1}
  1. Change the child's (the process watching for changes in web pages) terminate/2 method to
terminate(normal, _State) ->
  %% process terminated normally
  ok;
terminate(_Reason, _State) ->
  %% spawn the child again
  do_supverisor_start_child(),
  ok.