Hi!
I’m working on an application which has two dynamic supervisors.
Dynamic supervisors are required, as the application should be able to start children at runtime. Below you’ll find the init function of the “main” supervisor:
def init(_) do
children = [
supervisor(MyApp.OneThing.Supervisor, []),
supervisor(MyApp.OtherThing.Supervisor, []),
worker(MyApp.Coordinator, [])
]
supervise(children, strategy: :one_for_one)
end
For some persistence reasons, the application persists the state of each child using Ecto in conjunction with PostgreSQL. Now, I want to load the stored states of each child on application startup and use it to start a “new” child with the previously stored state. In order to solve this, I’ve setup the simple GenServer MyApp.Coordinator
which load the stored states from database and then starts a child for each entry. This solution works as expected, but in order to improve my Elixir/Erlang skills:
Is there another, maybe more idiomatic way to start children of dynamic supervisors on application startup?
Many thanks for your thoughts…