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
# 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
config :aprsme,
default_from_email: "w5isp@aprs.me"

View file

@ -22,7 +22,7 @@ defmodule Aprsme.Application do
# Start the Ecto repository
Aprsme.Repo,
# Start the PubSub system
{Phoenix.PubSub, name: Aprsme.PubSub},
pubsub_config(),
# Start the rate limiter
Aprsme.RateLimiter,
# Start cache systems
@ -162,4 +162,20 @@ defmodule Aprsme.Application do
Logger.info("Automatic migrations disabled")
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

View file

@ -38,11 +38,11 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do
# Handle packet visibility logic
socket = handle_packet_visibility(packet, lat, lon, callsign_key, socket)
# Update last update timestamp for real-time display in map sidebar
# This timestamp is shown to users to indicate when data was last refreshed
socket = assign(socket, :last_update_at, DateTime.utc_now())
{:noreply, socket}
end