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.Terrain.TerrainAnalysis
|
||||||
alias Microwaveprop.Weather
|
alias Microwaveprop.Weather
|
||||||
alias Microwaveprop.Weather.HrrrClient
|
alias Microwaveprop.Weather.HrrrClient
|
||||||
|
alias Microwaveprop.Workers.ContactWeatherEnqueueWorker
|
||||||
alias Microwaveprop.Workers.HrrrFetchWorker
|
alias Microwaveprop.Workers.HrrrFetchWorker
|
||||||
alias Microwaveprop.Workers.TerrainProfileWorker
|
alias Microwaveprop.Workers.TerrainProfileWorker
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
||||||
contact: contact,
|
contact: contact,
|
||||||
surface_observations: weather.surface_observations,
|
surface_observations: weather.surface_observations,
|
||||||
soundings: weather.soundings,
|
soundings: weather.soundings,
|
||||||
weather_status: weather_status(weather, contact),
|
weather_status: maybe_enqueue_weather(weather, contact),
|
||||||
solar: solar,
|
solar: solar,
|
||||||
hrrr: hrrr,
|
hrrr: hrrr,
|
||||||
hrrr_status: hrrr_status,
|
hrrr_status: hrrr_status,
|
||||||
|
|
@ -179,14 +180,20 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp weather_status(weather, contact) do
|
defp maybe_enqueue_weather(weather, contact) do
|
||||||
has_data = weather.surface_observations != [] or weather.soundings != []
|
has_data = weather.surface_observations != [] or weather.soundings != []
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
has_data -> :loaded
|
has_data ->
|
||||||
contact.weather_queued -> :queued
|
:loaded
|
||||||
contact.pos1 -> :queued
|
|
||||||
true -> :unavailable
|
contact.pos1 ->
|
||||||
|
jobs = ContactWeatherEnqueueWorker.build_weather_jobs([contact])
|
||||||
|
if jobs != [], do: Oban.insert_all(jobs)
|
||||||
|
:queued
|
||||||
|
|
||||||
|
true ->
|
||||||
|
:unavailable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue