prop/priv/repo/migrations/20260418143251_create_propagation_run_timings.exs
Graham McIntire fc91f204fd
feat(propagation): record per-forecast-hour chain step timings
Add a propagation_run_timings table so the wall-clock duration of each
(run_time, forecast_hour) step is queryable long after the run is over.
Keyed by (run_time, forecast_hour) with a status column that captures
whether the step succeeded or bailed out, and an error string on
failure.

PropagationGridWorker stamps every step (ok and failed) via
Propagation.record_run_timing/1. Timing inserts are wrapped in rescue +
changeset-error handling so the instrumentation can never brick the
chain.
2026-04-18 09:36:52 -05:00

32 lines
1.2 KiB
Elixir

defmodule Microwaveprop.Repo.Migrations.CreatePropagationRunTimings do
use Ecto.Migration
def change do
create table(:propagation_run_timings, primary_key: false) do
add :id, :binary_id, primary_key: true
# `run_time` is the HRRR model cycle the chain is rolling through,
# `forecast_hour` ∈ 0..18 picks the step within that chain.
# (run_time, forecast_hour) is the natural key.
add :run_time, :utc_datetime, null: false
add :forecast_hour, :integer, null: false
add :valid_time, :utc_datetime, null: false
# Wall-clock window of this forecast hour's work, plus the total
# in ms so queries don't have to recompute it.
add :started_at, :utc_datetime_usec, null: false
add :finished_at, :utc_datetime_usec, null: false
add :duration_ms, :integer, null: false
# "ok" when replace_scores returned {:ok, _}, "failed" otherwise.
# `error` carries the inspected reason on failure, nil on success.
add :status, :string, null: false
add :error, :text
timestamps(type: :utc_datetime, updated_at: false)
end
create unique_index(:propagation_run_timings, [:run_time, :forecast_hour])
create index(:propagation_run_timings, [:started_at])
end
end