Erlang管理程序重新启动间隔

1sbrub3j  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(155)

我有一个使用one_for_one重启策略的管理程序。是否可以在子进程重启之间设置一些时间间隔?
例如,远程数据库崩溃,我想在恢复连接尝试之间等待10秒。

gzjq41n4

gzjq41n41#

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.

相关问题