aprs.me/lib/aprsme/cluster/packet_receiver.ex
Graham McIntire 81a4b7b815
Fix credo issues
- Remove trailing whitespace from comments
- Fix long line in packet_processor.ex
- Rename is_leader? to leader? following Elixir conventions
2026-02-09 11:17:56 -06:00

41 lines
1,006 B
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.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 !Aprsme.Cluster.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