From f897a9a32157b672f551ff951f8351b2c251002e Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 2 Apr 2026 15:07:49 -0500 Subject: [PATCH] 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. --- .../live/contact_live/show.ex | 61 ++++++------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/lib/microwaveprop_web/live/contact_live/show.ex b/lib/microwaveprop_web/live/contact_live/show.ex index 7665887f..535cfc03 100644 --- a/lib/microwaveprop_web/live/contact_live/show.ex +++ b/lib/microwaveprop_web/live/contact_live/show.ex @@ -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