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.
63 lines
1.6 KiB
Elixir
63 lines
1.6 KiB
Elixir
defmodule Aprsme.CleanupScheduler do
|
|
@moduledoc """
|
|
GenServer that schedules periodic packet cleanup tasks.
|
|
|
|
This scheduler runs cleanup tasks directly every 6 hours by default
|
|
without requiring external job queues.
|
|
"""
|
|
|
|
use GenServer
|
|
|
|
alias Aprsme.Workers.PacketCleanupWorker
|
|
|
|
require Logger
|
|
|
|
def start_link(opts) do
|
|
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
|
|
end
|
|
|
|
@impl true
|
|
def init(_opts) do
|
|
config = Application.get_env(:aprsme, :cleanup_scheduler, [])
|
|
enabled = Keyword.get(config, :enabled, true)
|
|
# 6 hours
|
|
interval = Keyword.get(config, :interval, 6 * 60 * 60 * 1000)
|
|
|
|
if enabled do
|
|
Logger.info("Starting packet cleanup scheduler with #{interval}ms interval")
|
|
schedule_next_cleanup(interval)
|
|
{:ok, %{interval: interval}}
|
|
else
|
|
Logger.info("Packet cleanup scheduler disabled")
|
|
{:ok, %{interval: nil}}
|
|
end
|
|
end
|
|
|
|
@impl true
|
|
def handle_info(:schedule_cleanup, %{interval: interval} = state) when is_integer(interval) do
|
|
Logger.info("Running packet cleanup task")
|
|
|
|
_ =
|
|
Aprsme.BroadcastTaskSupervisor.async_execute(fn ->
|
|
try do
|
|
PacketCleanupWorker.perform(%{})
|
|
rescue
|
|
error ->
|
|
Logger.error("Packet cleanup task failed: #{inspect(error)}")
|
|
end
|
|
end)
|
|
|
|
schedule_next_cleanup(interval)
|
|
{:noreply, state}
|
|
end
|
|
|
|
@impl true
|
|
def handle_info(:schedule_cleanup, state) do
|
|
# Scheduler is disabled
|
|
{:noreply, state}
|
|
end
|
|
|
|
defp schedule_next_cleanup(interval) do
|
|
Process.send_after(self(), :schedule_cleanup, interval)
|
|
end
|
|
end
|