Enqueue weather (ASOS/RAOB) fetch on page view when missing
This commit is contained in:
parent
43f7bcf3c8
commit
c42c5d8c4c
1 changed files with 13 additions and 6 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue