Enabled :error_handling, :unknown, :unmatched_returns, :extra_return, :missing_return in an earlier commit and landed a 129-warning baseline. Four parallel agents each fixed a directory slice: - Core contexts (29): Radio, Release, Weather, Beacons, Cache, Backtest.Features, Terrain.Srtm, Ionosphere.GiroClient, Propagation.RunTiming, Accounts.Scope, RepoListener. Fixes were (a) prefix side-effect calls (Task.start, Phoenix.PubSub, Logger, :ets.new) with _ = ; (b) tighten/widen specs that didn't match actual returns; (c) add missing @type t declarations; (d) drop dead parse_int(nil) clause. - Propagation + weather subdirs (15): FreshnessMonitor, NotifyListener, ScoreCache, ScoreCacheReconciler, Weather.FrontalAnalysis, Weather.Grib2.Extractor, Weather.Grib2.Wgrib2, GridCache, HrrrPointEnqueuer, NexradCache. Same patterns — mostly _ = on PubSub / :ets / Repo.insert_all; widened two specs (float -> number) where integer returns were reachable. - Workers (35): BackfillEnqueue, CanadianSoundingFetch, ContactImport, ContactWeatherEnqueue, GefsFetch, IemreFetch, NarrFetch, SolarIndex, TerrainProfile, WeatherFetch. Prefixed Repo.update_all / Radio.set_enrichment_status! / Weather.upsert_* side-effect calls. Fixed one :pattern_match in CanadianSoundingFetch.most_recent_sounding_time/1 where a tautological cond guard generated unreachable code. - Web + Mix tasks + lib_ml (46 of 50): controllers, LiveViews, UserAuth, and 11 mix tasks. Same prefix strategy. 4 remaining warnings originate in LiveTable.LiveResource dep macro expansion and can't be fixed without forking the dep — added .dialyzer_ignore.exs to suppress just those specific file:line pairs. Also wired ignore_warnings in mix.exs dialyzer config. mix dialyzer --format short | grep ^lib/ | wc -l -> 0 mix test: 2163 tests, 3 pre-existing flakes, 0 regressions.
74 lines
2.3 KiB
Elixir
74 lines
2.3 KiB
Elixir
defmodule Microwaveprop.Workers.IemreFetchWorker do
|
|
@moduledoc false
|
|
use Oban.Worker, queue: :iemre, max_attempts: 20
|
|
|
|
alias Microwaveprop.Weather
|
|
alias Microwaveprop.Weather.IemClient
|
|
|
|
require Logger
|
|
|
|
@impl Oban.Worker
|
|
def backoff(%Oban.Job{attempt: attempt}) do
|
|
min(120 * Integer.pow(2, attempt - 1), _six_hours = 21_600)
|
|
end
|
|
|
|
@impl Oban.Worker
|
|
def perform(%Oban.Job{args: args}) do
|
|
%{"lat" => lat, "lon" => lon, "date" => date_str} = args
|
|
date = Date.from_iso8601!(date_str)
|
|
|
|
if Weather.has_iemre_observation?(lat, lon, date) do
|
|
Logger.info("IEMRE observation already exists for #{lat},#{lon} @ #{date_str}")
|
|
:ok
|
|
else
|
|
Logger.info("Fetching IEMRE data for #{lat},#{lon} @ #{date_str}")
|
|
fetch_and_store_iemre(lat, lon, date, date_str)
|
|
end
|
|
end
|
|
|
|
defp fetch_and_store_iemre(lat, lon, date, date_str) do
|
|
case IemClient.fetch_iemre(lat, lon, date) do
|
|
{:ok, []} ->
|
|
# Store stub so this lat/lon/date isn't retried on future backfills
|
|
_ = Weather.upsert_iemre_observation(%{lat: lat, lon: lon, date: date, hourly: []})
|
|
Logger.info("IEMRE: no data available for #{lat},#{lon} @ #{date_str}, stored stub")
|
|
:ok
|
|
|
|
{:ok, data} ->
|
|
_ =
|
|
Weather.upsert_iemre_observation(%{
|
|
lat: lat,
|
|
lon: lon,
|
|
date: date,
|
|
hourly: data
|
|
})
|
|
|
|
Logger.info("IEMRE observation saved for #{lat},#{lon} @ #{date_str} (#{length(data)} hours)")
|
|
:ok
|
|
|
|
{:error, reason} ->
|
|
handle_error(reason, lat, lon, date_str)
|
|
end
|
|
end
|
|
|
|
defp handle_error(reason, lat, lon, date_str) do
|
|
if transient_failure?(reason) do
|
|
Logger.error("IEMRE transient error for #{lat},#{lon} @ #{date_str}: #{inspect(reason)}")
|
|
{:error, reason}
|
|
else
|
|
Logger.warning("IEMRE permanent failure for #{lat},#{lon} @ #{date_str}: #{inspect(reason)}")
|
|
{:cancel, reason}
|
|
end
|
|
end
|
|
|
|
defp transient_failure?(%{__exception__: true}), do: true
|
|
defp transient_failure?("IEM IEMRE HTTP " <> status), do: server_error?(status)
|
|
defp transient_failure?(_), do: false
|
|
|
|
defp server_error?(status) do
|
|
case Integer.parse(status) do
|
|
{code, _} when code in [429, 500, 502, 503, 504] -> true
|
|
_ -> false
|
|
end
|
|
end
|
|
end
|