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:
parent
89eafcb1b0
commit
4ba7269e57
1 changed files with 11 additions and 1 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue