From 8d008ba9348f04ac9f8d9991f17499b4a48d07d8 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 5 Apr 2026 10:26:10 -0500 Subject: [PATCH] Add logging to WeatherFetchWorker for ASOS and RAOB fetches --- .../workers/weather_fetch_worker.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/microwaveprop/workers/weather_fetch_worker.ex b/lib/microwaveprop/workers/weather_fetch_worker.ex index ab9810c6..65e3c94b 100644 --- a/lib/microwaveprop/workers/weather_fetch_worker.ex +++ b/lib/microwaveprop/workers/weather_fetch_worker.ex @@ -5,6 +5,8 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do max_attempts: 20, unique: [period: 300, states: [:available, :scheduled, :executing, :retryable]] + require Logger + alias Microwaveprop.Repo alias Microwaveprop.Weather alias Microwaveprop.Weather.IemClient @@ -30,18 +32,26 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do case Repo.get(Station, station_id) do nil -> + Logger.warning("WeatherFetch ASOS: station #{station_id} not found, skipping") :ok station -> if Weather.has_surface_observations?(station.id, start_dt, end_dt) do + Logger.debug("WeatherFetch ASOS: #{station_code} already has obs for #{start_dt_str}..#{end_dt_str}") :ok else + Logger.info("WeatherFetch ASOS: fetching #{station_code} for #{start_dt_str}..#{end_dt_str}") + case IemClient.fetch_asos(station_code, start_dt, end_dt) do {:ok, rows} -> + count = Enum.count(rows, & &1.observed_at) + Enum.each(rows, fn row -> if row.observed_at, do: Weather.upsert_surface_observation(station, row) end) + Logger.info("WeatherFetch ASOS: #{station_code} ingested #{count} observations") + Phoenix.PubSub.broadcast( Microwaveprop.PubSub, "contact_enrichment:weather", @@ -51,6 +61,7 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do :ok {:error, reason} -> + Logger.warning("WeatherFetch ASOS: #{station_code} failed: #{inspect(reason)}") {:error, reason} end end @@ -68,12 +79,16 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do case Repo.get(Station, station_id) do nil -> + Logger.warning("WeatherFetch RAOB: station #{station_id} not found, skipping") :ok station -> if Weather.has_sounding?(station.id, sounding_time) do + Logger.debug("WeatherFetch RAOB: #{station_code} already has sounding for #{sounding_time_str}") :ok else + Logger.info("WeatherFetch RAOB: fetching #{station_code} for #{sounding_time_str}") + case IemClient.fetch_raob(station_code, sounding_time) do {:ok, [parsed | _]} -> params = SoundingParams.derive(parsed.profile) @@ -106,6 +121,8 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do Weather.upsert_sounding(station, sounding_attrs) + Logger.info("WeatherFetch RAOB: #{station_code} ingested sounding with #{length(parsed.profile)} levels") + Phoenix.PubSub.broadcast( Microwaveprop.PubSub, "contact_enrichment:weather", @@ -115,9 +132,11 @@ defmodule Microwaveprop.Workers.WeatherFetchWorker do :ok {:ok, []} -> + Logger.info("WeatherFetch RAOB: #{station_code} returned no data for #{sounding_time_str}") :ok {:error, reason} -> + Logger.warning("WeatherFetch RAOB: #{station_code} failed: #{inspect(reason)}") {:error, reason} end end