Enqueue weather (ASOS/RAOB) fetch on page view when missing

This commit is contained in:
Graham McIntire 2026-04-02 11:02:05 -05:00
parent 43f7bcf3c8
commit c42c5d8c4c
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -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