Move Redis PubSub config to runtime initialization

- Remove static Redis PubSub configuration from runtime.exs
- Add dynamic pubsub_config/0 function in application.ex
- Configure PubSub adapter based on cluster_enabled and REDIS_URL at startup
- Ensures proper initialization order for distributed deployments

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-26 10:10:55 -05:00
parent 194ff0006f
commit c85b907ab7
No known key found for this signature in database
3 changed files with 19 additions and 18 deletions

View file

@ -122,21 +122,6 @@ if config_env() == :prod do
config :aprsme, :cluster_enabled, cluster_enabled config :aprsme, :cluster_enabled, cluster_enabled
# Configure Redis PubSub when clustering is enabled
if cluster_enabled and System.get_env("REDIS_URL") do
config :aprsme, AprsmeWeb.Endpoint,
pubsub_server: Aprsme.PubSub,
pubsub: [
name: Aprsme.PubSub,
adapter: Phoenix.PubSub.Redis,
redis_pool_size: 10,
node_name: node(),
redis_options: [
url: System.get_env("REDIS_URL")
]
]
end
# Optional: Set the default "from" email address # Optional: Set the default "from" email address
config :aprsme, config :aprsme,
default_from_email: "w5isp@aprs.me" default_from_email: "w5isp@aprs.me"

View file

@ -22,7 +22,7 @@ defmodule Aprsme.Application do
# Start the Ecto repository # Start the Ecto repository
Aprsme.Repo, Aprsme.Repo,
# Start the PubSub system # Start the PubSub system
{Phoenix.PubSub, name: Aprsme.PubSub}, pubsub_config(),
# Start the rate limiter # Start the rate limiter
Aprsme.RateLimiter, Aprsme.RateLimiter,
# Start cache systems # Start cache systems
@ -162,4 +162,20 @@ defmodule Aprsme.Application do
Logger.info("Automatic migrations disabled") Logger.info("Automatic migrations disabled")
end end
defp pubsub_config do
cluster_enabled = Application.get_env(:aprsme, :cluster_enabled, false)
redis_url = System.get_env("REDIS_URL")
if cluster_enabled and redis_url do
{Phoenix.PubSub,
name: Aprsme.PubSub,
adapter: Phoenix.PubSub.Redis,
redis_pool_size: 10,
node_name: node(),
redis_options: [url: redis_url]}
else
{Phoenix.PubSub, name: Aprsme.PubSub}
end
end
end end