Software design fixes: - Add proper aliases for all nested modules - release.ex: Ecto.Adapters.SQL - packet_consumer.ex: Aprsme.Cluster.PacketDistributor - cleanup_scheduler.ex: Aprsme.Workers.PacketCleanupWorker - health_check.ex: Ecto.Adapters.SQL - status_live/index.ex: Aprsme.Cluster.LeaderElection - packet_receiver.ex: Aprsme.Cluster.LeaderElection - packet_distributor.ex: Aprsme.Cluster.LeaderElection, AprsmeWeb.MapLive.PacketStore Security: - Update .sobelow-skips for false positive SQL injection warning (div is builtin function) All 13 software design suggestions now complete. All 13 warnings previously fixed. Remaining: 42 refactoring opportunities (complex/nested functions)
42 lines
1 KiB
Elixir
42 lines
1 KiB
Elixir
defmodule Aprsme.Cluster.PacketReceiver do
|
|
@moduledoc """
|
|
Receives distributed packets from the cluster leader on non-leader nodes.
|
|
Ensures all nodes can serve real-time updates even though only the leader
|
|
processes APRS packets.
|
|
"""
|
|
use GenServer
|
|
|
|
alias Aprsme.Cluster.LeaderElection
|
|
alias Aprsme.Cluster.PacketDistributor
|
|
|
|
require Logger
|
|
|
|
def start_link(opts) do
|
|
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
|
|
end
|
|
|
|
@impl true
|
|
def init(_opts) do
|
|
# Subscribe to distributed packets
|
|
PacketDistributor.subscribe()
|
|
|
|
Logger.info("Started packet receiver on node #{node()}")
|
|
|
|
{:ok, %{}}
|
|
end
|
|
|
|
@impl true
|
|
def handle_info({:distributed_packet, packet}, state) do
|
|
# Only process if we're not the leader (leader already processed locally)
|
|
if !LeaderElection.leader?() do
|
|
PacketDistributor.handle_distributed_packet({:distributed_packet, packet})
|
|
end
|
|
|
|
{:noreply, state}
|
|
end
|
|
|
|
@impl true
|
|
def handle_info(_msg, state) do
|
|
{:noreply, state}
|
|
end
|
|
end
|