tres/message_handler: Fix to use DynamicSupervisor instead of :simple_one_for_one

This commit is contained in:
Eishun Kondoh 2018-05-02 16:22:31 +09:00
parent 6bba512271
commit a316bf2416
6 changed files with 10 additions and 11 deletions

View file

@ -10,7 +10,7 @@ defmodule Tres.ExampleHandler do
conn_ref: nil
end
def start_link(datapath, args) do
def start_link([datapath, args]) do
GenServer.start_link(__MODULE__, [datapath, args])
end

View file

@ -1,17 +1,16 @@
defmodule Tres.MessageHandlerSup do
use Supervisor
use DynamicSupervisor
def start_link(cb_mod) do
Supervisor.start_link(__MODULE__, [cb_mod], name: __MODULE__)
DynamicSupervisor.start_link(__MODULE__, [cb_mod], name: __MODULE__)
end
def init([cb_mod]) do
children = [worker(cb_mod, [], restart: :temporary, shutdown: 5000)]
supervise(children, strategy: :simple_one_for_one)
def init([_cb_mod]) do
DynamicSupervisor.init(strategy: :one_for_one)
end
def start_child({dpid, aux_id}) do
{_cb_mod, cb_args} = Tres.Utils.get_callback_module()
Supervisor.start_child(__MODULE__, [{dpid, aux_id}, cb_args])
{cb_mod, cb_args} = Tres.Utils.get_callback_module()
DynamicSupervisor.start_child(__MODULE__, {cb_mod, [{dpid, aux_id}, cb_args]})
end
end