CouncilEx.Persistence.Schema.Run (CouncilEx v0.1.0)

Copy Markdown View Source

Ecto schema for the <prefix>runs table.

One row per (council, attempt) pair. Survives Oban job pruning by design — :oban_job_id is a plain bigint, not a foreign key. Use :oban_job_state_at_finalize for post-mortem when the job row is gone.

Statuses

  • :queued — job enqueued but not yet picked up
  • :running — recorder has received :run_started
  • :completed:run_completed event seen
  • :failed:run_failed with non-cancel errors
  • :cancelled:run_failed containing a :cancelled error
  • :stuck — boot-time reconciliation found this row in :running with no live Oban job

Retry semantics

Per docs/MULTI_REPLICA_RECORDER.md, each Oban attempt gets a fresh run_id. The original run id is recorded in :parent_attempt_run_id to link the chain.

Summary

Functions

Statuses considered active (still consuming resources).

Build a changeset for inserts and updates.

Statuses that indicate the run is no longer active.

Types

t()

@type t() :: %CouncilEx.Persistence.Schema.Run{
  __meta__: term(),
  attempt: term(),
  council: term(),
  error: term(),
  finalized_at: term(),
  input: term(),
  inserted_at: term(),
  oban_job_id: term(),
  oban_job_state_at_finalize: term(),
  parent_attempt_run_id: term(),
  result: term(),
  run_id: term(),
  started_at: term(),
  status: term(),
  updated_at: term()
}

Functions

active_statuses()

@spec active_statuses() :: [atom()]

Statuses considered active (still consuming resources).

changeset(run, attrs)

@spec changeset(
  t()
  | %CouncilEx.Persistence.Schema.Run{
      __meta__: term(),
      attempt: term(),
      council: term(),
      error: term(),
      finalized_at: term(),
      input: term(),
      inserted_at: term(),
      oban_job_id: term(),
      oban_job_state_at_finalize: term(),
      parent_attempt_run_id: term(),
      result: term(),
      run_id: term(),
      started_at: term(),
      status: term(),
      updated_at: term()
    },
  map()
) :: Ecto.Changeset.t()

Build a changeset for inserts and updates.

terminal_statuses()

@spec terminal_statuses() :: [atom()]

Statuses that indicate the run is no longer active.