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:
parent
194ff0006f
commit
c85b907ab7
3 changed files with 19 additions and 18 deletions
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,11 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do
|
||||||
|
|
||||||
# Handle packet visibility logic
|
# Handle packet visibility logic
|
||||||
socket = handle_packet_visibility(packet, lat, lon, callsign_key, socket)
|
socket = handle_packet_visibility(packet, lat, lon, callsign_key, socket)
|
||||||
|
|
||||||
# Update last update timestamp for real-time display in map sidebar
|
# Update last update timestamp for real-time display in map sidebar
|
||||||
# This timestamp is shown to users to indicate when data was last refreshed
|
# This timestamp is shown to users to indicate when data was last refreshed
|
||||||
socket = assign(socket, :last_update_at, DateTime.utc_now())
|
socket = assign(socket, :last_update_at, DateTime.utc_now())
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue