aprs.me/lib/aprsme/postgres_notifier.ex
Graham McIntire b8a9b8a465
chore(dialyzer): enable stricter flags and fix 97 resulting findings
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.
2026-04-21 10:07:01 -05:00

34 lines
1.1 KiB
Elixir

defmodule Aprsme.PostgresNotifier do
@moduledoc """
Listens to PostgreSQL NOTIFY events on the "aprs_events" channel (used by
bad_packets) and broadcasts them via Phoenix.PubSub.
Packet notifications previously came through here via the "aprs_packets"
channel + `packets_notify_insert` trigger. That path was removed to avoid
per-row trigger overhead and double-broadcasting — packets are now
broadcast directly from `Aprsme.PacketConsumer` to the same topics.
"""
use GenServer
@event_channel "aprs_events"
@event_topic "postgres:aprsme_events"
def start_link(_opts) do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
end
@impl true
def init(_) do
{:ok, conn} = Postgrex.Notifications.start_link(Aprsme.Repo.config())
{:ok, _ref} = Postgrex.Notifications.listen(conn, @event_channel)
{:ok, %{conn: conn}}
end
@impl true
def handle_info({:notification, _conn, _pid, @event_channel, payload}, state) do
_ = Phoenix.PubSub.broadcast(Aprsme.PubSub, @event_topic, {:postgres_notify, payload})
{:noreply, state}
end
def handle_info(_msg, state), do: {:noreply, state}
end