Skip to content

Commit

Permalink
connection supervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
benonymus committed Dec 13, 2023
1 parent 8b707df commit c526268
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/nsq/connection/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ defmodule NSQ.Connection.Supervisor do
use Supervisor
alias NSQ.ConnInfo, as: ConnInfo


# ------------------------------------------------------- #
# Behaviour Implementation #
# ------------------------------------------------------- #
def start_link(opts \\ []) 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,
Expand All @@ -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

0 comments on commit c526268

Please sign in to comment.