fix(backfill): mark path enrichments :unavailable when pos2 is missing

Contacts lacking pos2 had terrain/radar/mechanism stuck on :pending, so
BackfillEnqueueWorker re-scanned them every cron cycle. Mark these
statuses :unavailable so the enqueue filter excludes them; a later pos2
edit resets them back to :pending via Radio.reset_enrichment_statuses/2.
This commit is contained in:
Graham McIntire 2026-04-20 15:02:29 -05:00
parent c10cf176e7
commit 9950aa11c2
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
2 changed files with 25 additions and 8 deletions

View file

@ -97,9 +97,23 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorker do
if contact.pos1 && contact.pos2 do
mark_path_statuses(contact, ids, types, jobs_by_type)
else
# Path enrichments (terrain/radar/mechanism) need both endpoints.
# Marking :unavailable stops BackfillEnqueueWorker from re-scanning
# these contacts every cron cycle. Radio.reset_enrichment_statuses/2
# will flip them back to :pending if pos2 is added later.
mark_missing_path_statuses(ids, types)
end
end
defp mark_missing_path_statuses(ids, types) do
if :terrain in types, do: Radio.set_enrichment_status!(ids, :terrain_status, :unavailable)
if :radar in types, do: Radio.set_enrichment_status!(ids, :radar_status, :unavailable)
if :mechanism in types,
do: Radio.set_enrichment_status!(ids, :propagation_mechanism_status, :unavailable)
end
defp mark_pos1_statuses(contact, ids, types, jobs_by_type) do
if :weather in types, do: mark_status!(ids, :weather_status, jobs_by_type[:weather])
if :hrrr in types, do: mark_hrrr_status!(contact, ids, jobs_by_type[:hrrr])

View file

@ -370,13 +370,13 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorkerTest do
assert updated.terrain_status == :queued
end
test "skips terrain for QSOs missing pos2" do
_qso = create_contact(%{pos2: nil})
test "marks terrain :unavailable for QSOs missing pos2" do
contact = create_contact(%{pos2: nil, grid2: nil})
assert :ok = ContactWeatherEnqueueWorker.perform(%Oban.Job{args: %{}})
assert :ok = ContactWeatherEnqueueWorker.enqueue_for_contact(contact)
all_contacts = Repo.all(Contact)
refute Enum.any?(all_contacts, &(&1.terrain_status == :queued))
updated = Repo.get!(Contact, contact.id)
assert updated.terrain_status == :unavailable
end
end
@ -682,7 +682,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorkerTest do
assert updated.iemre_status == :queued
end
test "works for QSO without pos2 or grid2 (terrain stays pending)" do
test "works for QSO without pos2 or grid2 (path statuses flip to :unavailable)" do
_station = create_asos_station("KDFW", 32.90, -97.04)
contact = create_contact(%{pos2: nil, grid2: nil})
@ -691,9 +691,12 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorkerTest do
updated = Repo.get!(Contact, contact.id)
assert updated.weather_status == :queued
assert updated.hrrr_status == :queued
# terrain requires pos2, so it can't be queued
assert updated.terrain_status == :pending
assert updated.iemre_status == :queued
# Path-dependent enrichments need pos2 — marking :unavailable keeps
# BackfillEnqueueWorker from re-scanning these contacts every cron.
assert updated.terrain_status == :unavailable
assert updated.radar_status == :unavailable
assert updated.propagation_mechanism_status == :unavailable
end
# Pre-2014 contacts have no HRRR data ever; mark hrrr_status :unavailable