refactor(contacts): rename propagation_mechanism_status -> mechanism_status
Column name now matches the type key used everywhere else:
:hrrr -> hrrr_status, :weather -> weather_status,
:terrain -> terrain_status, :mechanism -> mechanism_status
Drops the @status_column_overrides remap in BackfillEnqueueWorker
(status_column/1 is now a straight :"#{type}_status" derivation) and
the long-form references in Contact, ContactWeatherEnqueueWorker,
and MechanismClassifyWorker. Migration is a metadata-only RENAME
COLUMN + RENAME INDEX — safe to land in prod (no table rewrite,
brief catalog lock only).
This commit is contained in:
parent
360a0e32c1
commit
f4f44b5ebe
7 changed files with 31 additions and 17 deletions
|
|
@ -52,7 +52,7 @@ defmodule Microwaveprop.Radio.Contact do
|
|||
field :propagation_mechanism, :string
|
||||
field :propagation_mechanism_confidence, Ecto.Enum, values: [:high, :medium, :low]
|
||||
|
||||
field :propagation_mechanism_status, Ecto.Enum,
|
||||
field :mechanism_status, Ecto.Enum,
|
||||
values: [:pending, :queued, :processing, :complete, :failed, :unavailable],
|
||||
default: :pending
|
||||
|
||||
|
|
|
|||
|
|
@ -33,12 +33,6 @@ defmodule Microwaveprop.Workers.BackfillEnqueueWorker do
|
|||
# Skip these in any reconcile / ordering pass that reads a <type>_status field.
|
||||
@virtual_types [:narr]
|
||||
|
||||
# `radar` and `mechanism` use differently-named *_status columns than
|
||||
# `<type>_status`, so we remap them when building queries and update_alls.
|
||||
@status_column_overrides %{
|
||||
mechanism: :propagation_mechanism_status
|
||||
}
|
||||
|
||||
# A :queued contact whose updated_at is older than this is one the cron has
|
||||
# already tried ~144 times over 3 days without the underlying worker landing
|
||||
# data. At that point the data is effectively unreachable (dead ASOS station,
|
||||
|
|
@ -118,7 +112,7 @@ defmodule Microwaveprop.Workers.BackfillEnqueueWorker do
|
|||
end
|
||||
end
|
||||
|
||||
defp status_column(type), do: Map.get(@status_column_overrides, type, :"#{type}_status")
|
||||
defp status_column(type), do: :"#{type}_status"
|
||||
|
||||
# Flip contacts that have been stuck in :queued for longer than
|
||||
# @stale_queued_cutoff_seconds to :unavailable. One Repo.update_all per type,
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorker do
|
|||
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)
|
||||
do: Radio.set_enrichment_status!(ids, :mechanism_status, :unavailable)
|
||||
end
|
||||
|
||||
defp mark_pos1_statuses(contact, ids, types, jobs_by_type) do
|
||||
|
|
@ -131,7 +131,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorker do
|
|||
if :radar in types, do: mark_radar_status!(contact, ids, jobs_by_type[:radar])
|
||||
|
||||
if :mechanism in types,
|
||||
do: mark_status!(ids, :propagation_mechanism_status, jobs_by_type[:mechanism])
|
||||
do: mark_status!(ids, :mechanism_status, jobs_by_type[:mechanism])
|
||||
end
|
||||
|
||||
# IEM n0q composite reflectivity archive only has meaningful CONUS
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorker do
|
|||
* `active_meteor_shower` — looked up from the static shower calendar
|
||||
|
||||
Results land on the contact as `propagation_mechanism` (string),
|
||||
`propagation_mechanism_confidence` (enum), and
|
||||
`propagation_mechanism_status`.
|
||||
`propagation_mechanism_confidence` (enum), and `mechanism_status`.
|
||||
|
||||
Unique on `contact_id` so the submit-time enqueue path and the
|
||||
backfill cron collapse to a single job per contact.
|
||||
|
|
@ -236,7 +235,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorker do
|
|||
defp mark_status(%Contact{} = contact, status, mechanism, confidence) do
|
||||
contact
|
||||
|> Ecto.Changeset.change(%{
|
||||
propagation_mechanism_status: status,
|
||||
mechanism_status: status,
|
||||
propagation_mechanism: mechanism,
|
||||
propagation_mechanism_confidence: confidence
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
defmodule Microwaveprop.Repo.Migrations.RenamePropagationMechanismStatus do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
execute """
|
||||
ALTER INDEX contacts_propagation_mechanism_status_pending_index
|
||||
RENAME TO contacts_mechanism_status_pending_index
|
||||
"""
|
||||
|
||||
rename table(:contacts), :propagation_mechanism_status, to: :mechanism_status
|
||||
end
|
||||
|
||||
def down do
|
||||
rename table(:contacts), :mechanism_status, to: :propagation_mechanism_status
|
||||
|
||||
execute """
|
||||
ALTER INDEX contacts_mechanism_status_pending_index
|
||||
RENAME TO contacts_propagation_mechanism_status_pending_index
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
|
@ -736,7 +736,7 @@ defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorkerTest do
|
|||
# BackfillEnqueueWorker from re-scanning these contacts every cron.
|
||||
assert updated.terrain_status == :unavailable
|
||||
assert updated.radar_status == :unavailable
|
||||
assert updated.propagation_mechanism_status == :unavailable
|
||||
assert updated.mechanism_status == :unavailable
|
||||
end
|
||||
|
||||
# Pre-2014 contacts have no HRRR data ever; mark hrrr_status :unavailable
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do
|
|||
|
||||
reloaded = Repo.get!(Contact, contact.id)
|
||||
assert reloaded.propagation_mechanism == "rain_scatter"
|
||||
assert reloaded.propagation_mechanism_status == :complete
|
||||
assert reloaded.mechanism_status == :complete
|
||||
assert reloaded.propagation_mechanism_confidence == :high
|
||||
end
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do
|
|||
|
||||
reloaded = Repo.get!(Contact, contact.id)
|
||||
assert reloaded.propagation_mechanism == "troposcatter"
|
||||
assert reloaded.propagation_mechanism_status == :complete
|
||||
assert reloaded.mechanism_status == :complete
|
||||
assert reloaded.propagation_mechanism_confidence == :low
|
||||
end
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ defmodule Microwaveprop.Workers.MechanismClassifyWorkerTest do
|
|||
})
|
||||
|
||||
reloaded = Repo.get!(Contact, contact.id)
|
||||
assert reloaded.propagation_mechanism_status == :unavailable
|
||||
assert reloaded.mechanism_status == :unavailable
|
||||
end
|
||||
|
||||
test "missing contact (deleted) returns :ok gracefully" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue