I have a gen_server module, it does some periodic work: reads from the db, writes to another and sleeps. I want to scale it, and start multiple instances of the server. I do it in the following way:
def children_spec do
0..@workers_number - 1
|> Enum.map(
fn (i) ->
process_name = String.to_atom("#{__MODULE__}.#{i}")
Supervisor.child_spec({__MODULE__, name: process_name}, id: {__MODULE__, i})
end
)
end
The module has that children_spec function, which returns list of the child specifications that will be added to the list of the top level application supervisor:
children = children ++ MyWorkerModule.children_spec()
Supervisor.init(children, strategy: :one_for_one)
Is there another way to do that? Also i thought about additional supervisor for the module with the :simple_one_for_one strategy