Snodo.Extensions.Tasks.Store.Postgres (snodo_tasks_postgres v0.2.0)

Copy Markdown View Source

Multi-node PostgreSQL persistence for the MCP Tasks extension.

This adapter accepts an application-owned Ecto.Repo; it never starts a repository or runs migrations. Task snapshots and their serializable work descriptors are stored atomically as versioned JSONB. Applied events are committed to a separate ledger in the same transaction as the aggregate update.

Claims use PostgreSQL row locks, database time, opaque UUID tokens, exact expiry matching, and monotonically increasing generations. Recovery uses FOR UPDATE SKIP LOCKED, allowing independently supervised runners on several nodes to consume the same queue without a coordinator process.

Recovery remains at least once. Applications must deduplicate external side effects with Snodo.Extensions.Tasks.Work.idempotency_key.

Summary

Functions

Audits a bounded page of aggregates and event ledgers without mutating them.

Checks that the application has run this adapter's current migration.

Returns applied event history through the same scoped read authority as get/3.

Builds immutable adapter configuration around an application-owned Repo.

Builds adapter configuration or raises ArgumentError.

Types

audit_report()

@type audit_report() :: %{
  checked: non_neg_integer(),
  errors: [map()],
  next_cursor: String.t() | nil
}

Functions

audit(config, opts \\ [])

@spec audit(Snodo.Extensions.Tasks.Store.Postgres.Config.t(), keyword()) ::
  {:ok, audit_report()} | {:error, term()}

Audits a bounded page of aggregates and event ledgers without mutating them.

check_schema(config)

@spec check_schema(Snodo.Extensions.Tasks.Store.Postgres.Config.t()) ::
  :ok | {:error, term()}

Checks that the application has run this adapter's current migration.

history(config, task_id, access)

@spec history(Snodo.Extensions.Tasks.Store.Postgres.Config.t(), String.t(), term()) ::
  {:ok, [map()]} | :not_found | {:error, term()}

Returns applied event history through the same scoped read authority as get/3.

new(opts)

@spec new(keyword()) ::
  {:ok, Snodo.Extensions.Tasks.Store.Postgres.Config.t()} | {:error, term()}

Builds immutable adapter configuration around an application-owned Repo.

new!(opts)

Builds adapter configuration or raises ArgumentError.