Re-enqueue enrichment jobs when status is queued but data missing
Previously, if a job was cancelled or lost while status was :queued, viewing the contact detail page would not re-enqueue. Now HRRR, weather/soundings, and terrain all re-enqueue when :queued with no data, relying on Oban uniqueness for deduplication.
This commit is contained in:
parent
1fa8681c54
commit
f897a9a321
1 changed files with 18 additions and 43 deletions
|
|
@ -193,7 +193,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
Radio.set_enrichment_status!([contact.id], :weather_status, :complete)
|
||||
%{contact | weather_status: :complete}
|
||||
|
||||
contact.pos1 && contact.weather_status in [:pending, :failed] ->
|
||||
contact.pos1 && contact.weather_status in [:pending, :failed, :queued] ->
|
||||
jobs = ContactWeatherEnqueueWorker.build_weather_jobs([contact])
|
||||
if jobs != [], do: Oban.insert_all(jobs)
|
||||
Radio.set_enrichment_status!([contact.id], :weather_status, :queued)
|
||||
|
|
@ -285,7 +285,7 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
end
|
||||
|
||||
defp maybe_enqueue_terrain(nil, contact) do
|
||||
if contact.pos1 && contact.pos2 && contact.terrain_status in [:pending, :failed] do
|
||||
if contact.pos1 && contact.pos2 && contact.terrain_status in [:pending, :failed, :queued] do
|
||||
Oban.insert(TerrainProfileWorker.new(%{"qso_id" => contact.id}))
|
||||
Radio.set_enrichment_status!([contact.id], :terrain_status, :queued)
|
||||
%{contact | terrain_status: :queued}
|
||||
|
|
@ -310,31 +310,24 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
lat = contact.pos1 && contact.pos1["lat"]
|
||||
lon = contact.pos1 && (contact.pos1["lon"] || contact.pos1["lng"])
|
||||
|
||||
cond do
|
||||
lat && lon && contact.hrrr_status in [:pending, :failed] ->
|
||||
valid_time = HrrrClient.nearest_hrrr_hour(contact.qso_timestamp)
|
||||
{rlat, rlon} = Weather.round_to_hrrr_grid(lat, lon)
|
||||
if lat && lon && contact.hrrr_status in [:pending, :failed, :queued] do
|
||||
valid_time = HrrrClient.nearest_hrrr_hour(contact.qso_timestamp)
|
||||
{rlat, rlon} = Weather.round_to_hrrr_grid(lat, lon)
|
||||
|
||||
{:ok, job} =
|
||||
Oban.insert(
|
||||
HrrrFetchWorker.new(%{
|
||||
"lat" => rlat,
|
||||
"lon" => rlon,
|
||||
"valid_time" => DateTime.to_iso8601(valid_time)
|
||||
})
|
||||
)
|
||||
{:ok, job} =
|
||||
Oban.insert(
|
||||
HrrrFetchWorker.new(%{
|
||||
"lat" => rlat,
|
||||
"lon" => rlon,
|
||||
"valid_time" => DateTime.to_iso8601(valid_time)
|
||||
})
|
||||
)
|
||||
|
||||
Radio.set_enrichment_status!([contact.id], :hrrr_status, :queued)
|
||||
jobs_ahead = if job.id, do: count_hrrr_jobs_ahead(job.id), else: 0
|
||||
{nil, %{contact | hrrr_status: :queued}, jobs_ahead}
|
||||
|
||||
lat && lon && contact.hrrr_status == :queued ->
|
||||
valid_time = HrrrClient.nearest_hrrr_hour(contact.qso_timestamp)
|
||||
{rlat, rlon} = Weather.round_to_hrrr_grid(lat, lon)
|
||||
{nil, contact, count_hrrr_jobs_ahead_by_args(rlat, rlon, valid_time)}
|
||||
|
||||
true ->
|
||||
{nil, contact, 0}
|
||||
Radio.set_enrichment_status!([contact.id], :hrrr_status, :queued)
|
||||
jobs_ahead = if job.id, do: count_hrrr_jobs_ahead(job.id), else: 0
|
||||
{nil, %{contact | hrrr_status: :queued}, jobs_ahead}
|
||||
else
|
||||
{nil, contact, 0}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -351,24 +344,6 @@ defmodule MicrowavepropWeb.ContactLive.Show do
|
|||
)
|
||||
end
|
||||
|
||||
defp count_hrrr_jobs_ahead_by_args(lat, lon, valid_time) do
|
||||
import Ecto.Query
|
||||
|
||||
args = %{"lat" => lat, "lon" => lon, "valid_time" => DateTime.to_iso8601(valid_time)}
|
||||
|
||||
job_id =
|
||||
Microwaveprop.Repo.one(
|
||||
from(j in Oban.Job,
|
||||
where: j.queue == "hrrr",
|
||||
where: j.state in ["available", "scheduled", "retryable", "executing"],
|
||||
where: fragment("? @> ?", j.args, ^args),
|
||||
select: j.id,
|
||||
limit: 1
|
||||
)
|
||||
)
|
||||
|
||||
if job_id, do: count_hrrr_jobs_ahead(job_id), else: 0
|
||||
end
|
||||
|
||||
defp load_solar(contact) do
|
||||
contact.qso_timestamp
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue