- SharedPacketHandler.handle_packet_update: dispatch on filter-result, and use maybe_enrich/2 dispatched on the enrich? boolean instead of an inner `if`. lookup_device_info/1 is now a trio of function heads. - Cluster.Topology.child_spec: build_spec/3 dispatches on (cluster_enabled?, topologies) tuples — no more nested `if`. - Cluster.PacketDistributor.distribute_packet: maybe_broadcast/2 dispatches on the leader-and-enabled check; the non-leader / disabled paths return :ok explicitly instead of relying on an `if` expression's implicit nil. Adds tests for SharedPacketHandler (filter/enrich/match paths, callsign_filter + callsign_and_weather_filter factories) and extends Cluster.Topology tests to cover the nil-topology and opts-merge cases. Coverage 66.41 → 66.81%.
38 lines
1.2 KiB
Elixir
38 lines
1.2 KiB
Elixir
defmodule Aprsme.Cluster.Topology do
|
|
@moduledoc """
|
|
Wrapper for Cluster.Supervisor that only starts when clustering is enabled.
|
|
"""
|
|
require Logger
|
|
|
|
def child_spec(opts) do
|
|
cluster_enabled = Application.get_env(:aprsme, :cluster_enabled, false)
|
|
topologies = Application.get_env(:libcluster, :topologies, [])
|
|
build_spec(cluster_enabled, topologies, opts)
|
|
end
|
|
|
|
# Clustering disabled — no-op spec.
|
|
defp build_spec(false, _topologies, opts), do: noop_spec(opts)
|
|
|
|
# Clustering enabled but no topologies configured — no-op + warning.
|
|
defp build_spec(true, topologies, opts) when topologies in [nil, []] do
|
|
Logger.warning("No libcluster topologies configured, clustering will not work")
|
|
noop_spec(opts)
|
|
end
|
|
|
|
# Clustering enabled with topologies — delegate to libcluster's supervisor.
|
|
defp build_spec(true, topologies, opts) do
|
|
Logger.info("Cluster.Topology starting with topologies: #{inspect(topologies)}")
|
|
supervisor_opts = Keyword.merge([name: Aprsme.ClusterSupervisor], opts)
|
|
{Cluster.Supervisor, [topologies, supervisor_opts]}
|
|
end
|
|
|
|
defp noop_spec(opts) do
|
|
%{
|
|
id: __MODULE__,
|
|
start: {__MODULE__, :start_link, [opts]},
|
|
type: :worker
|
|
}
|
|
end
|
|
|
|
def start_link(_opts), do: :ignore
|
|
end
|