Turned on :error_handling, :underspecs, and :unmatched_returns in mix.exs dialyzer config. The 97 warnings this surfaced were fixed in place rather than suppressed: - unmatched_return (79): explicit discard with `_ = ...` for fire-and-forget side effects (Process.cancel_timer, :ets.new, send/2), and pattern-matched `:ok = ...` for control-plane Phoenix.PubSub subscribe/unsubscribe/broadcast calls so a future return-shape change fails loud. - contract_supertype (18): tightened @spec arg and return types on data_builder, historical_loader, url_params, packet_utils, encoding_utils, aprs_symbol, weather_controller, packet_replay to match each function's actual success typing. No behavioural change. mix compile clean, 1008 tests pass, dialyzer count is now 0.
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
|
|
:ok = 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
|