From c5262689d18a53b04eeeb70ffa51e8ee98f2f901 Mon Sep 17 00:00:00 2001 From: benonymus Date: Wed, 13 Dec 2023 14:49:32 +0700 Subject: [PATCH] connection supervisor --- lib/nsq/connection/supervisor.ex | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/nsq/connection/supervisor.ex b/lib/nsq/connection/supervisor.ex index b54ea99..18c3717 100644 --- a/lib/nsq/connection/supervisor.ex +++ b/lib/nsq/connection/supervisor.ex @@ -11,7 +11,6 @@ defmodule NSQ.Connection.Supervisor do use Supervisor alias NSQ.ConnInfo, as: ConnInfo - # ------------------------------------------------------- # # Behaviour Implementation # # ------------------------------------------------------- # @@ -19,10 +18,10 @@ defmodule NSQ.Connection.Supervisor do Supervisor.start_link(__MODULE__, :ok, opts) end - def start_child(parent, nsqd, parent_state \\ nil, opts \\ []) do parent_state = parent_state || GenServer.call(parent, :state) conn_sup_pid = parent_state.conn_sup_pid + args = [ parent, nsqd, @@ -32,18 +31,20 @@ defmodule NSQ.Connection.Supervisor do parent_state.conn_info_pid, parent_state.event_manager_pid ] + conn_id = ConnInfo.conn_id(parent, nsqd) # When using nsqlookupd, we expect connections will be naturally # rediscovered if they fail. - opts = [restart: :temporary, id: conn_id] ++ opts + config = + [id: conn_id, start: {NSQ.Connection, :start_link, args}, restart: :temporary] ++ opts + + child = Map.new(config) - child = worker(NSQ.Connection, args, opts) Supervisor.start_child(conn_sup_pid, child) end - def init(:ok) do - supervise([], strategy: :one_for_one) + Supervisor.init([], strategy: :one_for_one) end end