CouncilEx.Persistence.Recovery (CouncilEx v0.1.0)

Copy Markdown View Source

Boot-time reconciliation for orphaned run rows.

When a node crashes mid-run the runs row is left in :running with no live process. On the next boot, call reconcile_orphans/1 from your application supervisor (or wherever you initialise PostgreSQL state) to mark these rows as :stuck so UI / dashboards can distinguish "still running" from "abandoned".

Mirrors the pattern in Concilio.Chats.Recovery.

Usage

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    children = [
      MyApp.Repo,
      {Oban, oban_config()},
      # ...
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]

    with {:ok, sup} <- Supervisor.start_link(children, opts) do
      CouncilEx.Persistence.Recovery.reconcile_orphans()
      {:ok, sup}
    end
  end
end

Options

  • :repo — your Ecto.Repo. Defaults to the repo configured under config :council_ex, CouncilEx.Recorder.Ecto, repo: MyApp.Repo.
  • :table_prefix — defaults to "council_ex_".
  • :oban_jobs_table — defaults to "oban_jobs". Override when Oban is installed with a non-default table name.

Returns {:ok, count} where count is the number of rows updated to :stuck.

Summary

Functions

reconcile_orphans(opts \\ [])

@spec reconcile_orphans(keyword()) :: {:ok, non_neg_integer()} | {:error, term()}