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.
This commit is contained in:
Graham McIntire 2026-04-06 11:48:54 -05:00
parent 89eafcb1b0
commit 4ba7269e57

View file

@ -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"