Created
December 13, 2022 16:39
-
-
Save mazz/b3328e6aaeb28d54df4867f65ed89857 to your computer and use it in GitHub Desktop.
** (ArgumentError) unknown registry: Registry.MongoConnectionRegistry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Wrangler.Application do | |
# See https://hexdocs.pm/elixir/Application.html | |
# for more information on OTP Applications | |
@moduledoc false | |
use Application | |
@registry Registry.MongoConnectionRegistry | |
@impl true | |
def start(_type, _args) do | |
children = [ | |
# Start the Ecto repository | |
Wrangler.Repo, | |
# Start the Telemetry supervisor | |
WranglerWeb.Telemetry, | |
# Start the PubSub system | |
{Phoenix.PubSub, name: Wrangler.PubSub}, | |
# Start the Endpoint (http/https) | |
WranglerWeb.Endpoint, | |
{Task.Supervisor, name: Wrangler.BackgroundTask}, | |
{Oban, oban_config()}, | |
{Finch, name: Swoosh.Finch}, | |
{Registry, keys: :unique, name: @registry} | |
] | |
register_mongo_connection() | |
[{_pid, mongo_connection_pid}] = Registry.lookup(@registry, "open5gs_conn") | |
dbg(mongo_connection_pid) | |
# See https://hexdocs.pm/elixir/Supervisor.html | |
# for other strategies and supported options | |
opts = [strategy: :one_for_one, name: Wrangler.Supervisor] | |
Supervisor.start_link(children, opts) | |
end | |
# Tell Phoenix to update the endpoint configuration | |
# whenever the application is updated. | |
@impl true | |
def config_change(changed, _new, removed) do | |
WranglerWeb.Endpoint.config_change(changed, removed) | |
:ok | |
end | |
# Conditionally disable queues or plugins here. | |
defp oban_config do | |
Application.fetch_env!(:wrangler, Oban) | |
end | |
defp register_mongo_connection() do | |
if Mix.env() == :dev do | |
# mix/dev | |
{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/open5gs") | |
Registry.register(@registry, "open5gs_conn", conn) | |
else | |
# docker/prod | |
{:ok, conn} = | |
Mongo.start_link( | |
url: "mongodb://mongodb:27017/open5gs", | |
username: "secret", | |
password: "secret", | |
auth_source: "admin" | |
) | |
Registry.register(@registry, "open5gs_conn", conn) | |
end | |
end | |
end |
Author
mazz
commented
Dec 13, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment