Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang supervisor restart interval

I have a supervisor with one_for_one restart strategy. Is it possible to set some time interval between child process restarting?

For example, the remote db crushed and I want to wait 10 seconds between restore connection attempts.

like image 396
kolchanov Avatar asked Oct 10 '12 13:10

kolchanov


1 Answers

Actually, you could let the supervisor to immediately restart its children and implement what is called lazy initialization:

  1. The supervisor (re)starts (immediately) the child (say, a gen_server)
  2. The gen_server returns a 0 timeout in its init function
  3. In the handle_info you do an active wait (your 10 seconds) to ensure the DB is properly initialized

This way, you ensure that all requests to the gen_server are processed after the DB is properly initialized.

like image 129
Roberto Aloi Avatar answered Oct 26 '22 04:10

Roberto Aloi