From c42c5d8c4cdc29aea2dd70e76e23c0f01aef63b0 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 2 Apr 2026 11:02:05 -0500 Subject: [PATCH] Enqueue weather (ASOS/RAOB) fetch on page view when missing --- .../live/contact_live/show.ex | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/microwaveprop_web/live/contact_live/show.ex b/lib/microwaveprop_web/live/contact_live/show.ex index 24ac0085..0d5ba820 100644 --- a/lib/microwaveprop_web/live/contact_live/show.ex +++ b/lib/microwaveprop_web/live/contact_live/show.ex @@ -12,6 +12,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do alias Microwaveprop.Terrain.TerrainAnalysis alias Microwaveprop.Weather alias Microwaveprop.Weather.HrrrClient + alias Microwaveprop.Workers.ContactWeatherEnqueueWorker alias Microwaveprop.Workers.HrrrFetchWorker alias Microwaveprop.Workers.TerrainProfileWorker @@ -43,7 +44,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do contact: contact, surface_observations: weather.surface_observations, soundings: weather.soundings, - weather_status: weather_status(weather, contact), + weather_status: maybe_enqueue_weather(weather, contact), solar: solar, hrrr: hrrr, hrrr_status: hrrr_status, @@ -179,14 +180,20 @@ defmodule MicrowavepropWeb.ContactLive.Show do )} end - defp weather_status(weather, contact) do + defp maybe_enqueue_weather(weather, contact) do has_data = weather.surface_observations != [] or weather.soundings != [] cond do - has_data -> :loaded - contact.weather_queued -> :queued - contact.pos1 -> :queued - true -> :unavailable + has_data -> + :loaded + + contact.pos1 -> + jobs = ContactWeatherEnqueueWorker.build_weather_jobs([contact]) + if jobs != [], do: Oban.insert_all(jobs) + :queued + + true -> + :unavailable end end