Skip to content

Commit

Permalink
chg: [connections] supervisor update
Browse files Browse the repository at this point in the history
  • Loading branch information
gallypette committed Sep 13, 2024
1 parent d590d98 commit e9ad14a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ config :remote_ip, debug: false

# TimeZone data
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

config :tzdata, :autoupdate, :disabled
5 changes: 3 additions & 2 deletions lib/cocktailparty/broker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ defmodule Cocktailparty.Broker do

def init(opts) do
connection = opts[:connection]
dbg(connection)

{:ok, pubsub} =
PubSub.start_link(
host: connection.hostname,
port: connection.port,
host: connection.config["hostname"],
port: connection.config["port"],
name: {:global, "pubsub_" <> Integer.to_string(connection.id)}
)

Expand Down
6 changes: 3 additions & 3 deletions lib/cocktailparty/dynamic_supervisor_boot.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Cocktailparty.DynamicSupervisorBoot do
# alias Cocktailparty.Input.Connection
alias Cocktailparty.Input.Connection
use Supervisor

require Logger
Expand All @@ -20,8 +20,8 @@ defmodule Cocktailparty.DynamicSupervisorBoot do
Logger.info("Connection Dynamic Supervisor Task started")
# When starting we check what inputs are available
# for each instance, we start a redix connection along with a broker gen_server
# list_connections()
# |> Enum.each(fn x -> Connection.start(x) end)
Cocktailparty.Input.list_connections()
|> Enum.each(fn x -> Connection.start(x) end)
end}
]

Expand Down
51 changes: 29 additions & 22 deletions lib/cocktailparty/input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -205,27 +205,34 @@ defmodule Cocktailparty.Input do
Get the status of a redis connection
"""
# def connected?(%Connection{} = connection) do
def connected?(%Connection{} = _) do
# TODO refacto for connections
# case GenServer.whereis({:global, "redix_" <> Integer.to_string(connection.id)}) do
# nil ->
# false

# # name, node
# {_, _} ->
# true

# # pid
# pid ->
# case :sys.get_state(pid) do
# {:connected, _} ->
# true

# _ ->
# false
# end
# end
false
def connected?(%Connection{} = connection) do
case connection.type do
"redis" ->
case GenServer.whereis({:global, "redix_" <> Integer.to_string(connection.id)}) do
nil ->
false

# name, node
{_, _} ->
true

# pid
pid ->
case :sys.get_state(pid) do
{:connected, _} ->
true

_ ->
false
end
end

# TODO
"stomp" ->
false

_ ->
false
end
end
end
6 changes: 3 additions & 3 deletions lib/cocktailparty/input/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ defmodule Cocktailparty.Input.Connection do
supervisor_node = node(sup)

case :rpc.call(supervisor_node, DynamicSupervisor, :start_child, [
{:global, Cocktailparty.RedisInstancesDynamicSupervisor},
{:global, Cocktailparty.ConnectionsDynamicSupervisor},
spec_redix
]) do
{:ok, pid} ->
Logger.info("Redix driver alive for #{rc.name} with pid #{pid_to_string(pid)}")

case :rpc.call(supervisor_node, DynamicSupervisor, :start_child, [
{:global, Cocktailparty.RedisInstancesDynamicSupervisor},
{:global, Cocktailparty.ConnectionsDynamicSupervisor},
spec_broker
]) do
{:ok, pid_broker} ->
Expand Down Expand Up @@ -159,7 +159,7 @@ defmodule Cocktailparty.Input.Connection do

defp get_supervisor() do
# locate the reponsible broker process
case GenServer.whereis({:global, Cocktailparty.RedisInstancesDynamicSupervisor}) do
case GenServer.whereis({:global, Cocktailparty.ConnectionsDynamicSupervisor}) do
{name, node} ->
Logger.info("Supervisor is located at: #{node}/#{name}")
{name, node}
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Cocktailparty.MixProject do
]
end

defp extra_applications(:dev), do: [:observer, :wx]
defp extra_applications(:dev), do: [:observer, :wx, :debugger]
defp extra_applications(_), do: []

# Specifies which paths to compile per environment.
Expand Down Expand Up @@ -74,7 +74,7 @@ defmodule Cocktailparty.MixProject do
{:fun_with_flags_ui, "~> 0.8.1", runtime: false},
# Libcluster
{:libcluster, "~> 3.3"},
{:tzdata, "~> 1.1.1"},
{:tzdata, "~> 1.1.2"},
# STOMP support
{:barytherium, "~> 0.7.0"},
# YAML parsing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule CocktailpartyWeb.ConnectionControllerTest do
use CocktailpartyWeb.ConnCase
# use CocktailpartyWeb.DataCase

import Cocktailparty.InputFixtures

Expand Down

0 comments on commit e9ad14a

Please sign in to comment.