From 4ba7269e57aff593fce1d08d6f04d4f91bfb3b94 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 6 Apr 2026 11:48:54 -0500 Subject: [PATCH] Prioritize pending contacts over queued in backfill Queued contacts just need reconciliation (check if data exists), while pending contacts need actual HRRR fetches. Process pending first so real work happens before reconciliation. --- lib/microwaveprop/workers/backfill_enqueue_worker.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/microwaveprop/workers/backfill_enqueue_worker.ex b/lib/microwaveprop/workers/backfill_enqueue_worker.ex index c88266de..eeb58110 100644 --- a/lib/microwaveprop/workers/backfill_enqueue_worker.ex +++ b/lib/microwaveprop/workers/backfill_enqueue_worker.ex @@ -24,7 +24,7 @@ defmodule Microwaveprop.Workers.BackfillEnqueueWorker do Contact |> where([c], not is_nil(c.pos1) or not is_nil(c.grid1)) |> where(^type_filter(types)) - |> order_by([c], desc: c.qso_timestamp) + |> order_by(^status_priority_order(types)) |> limit(^limit) |> Repo.all() @@ -48,6 +48,16 @@ defmodule Microwaveprop.Workers.BackfillEnqueueWorker do defp parse_types(_), do: [:hrrr, :weather, :terrain, :iemre] + defp status_priority_order(types) do + # Prioritize pending/failed over queued so real work happens first + field = :"#{hd(types)}_status" + + [ + asc: dynamic([c], fragment("CASE ? WHEN 'pending' THEN 0 WHEN 'failed' THEN 1 ELSE 2 END", field(c, ^field))), + desc: dynamic([c], c.qso_timestamp) + ] + end + defp type_filter(types) do Enum.reduce(types, dynamic(false), fn type, acc -> field = :"#{type}_status"