What a transition's commit needs from the datastore.
Three operations: a transaction serialised per record, a re-read under it,
and the status write. An Ecto.Repo satisfies update/1 as is and needs
the other two added; a repo that already has them declares the behaviour:
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.Postgres
@behaviour Hoare.Store
@impl Hoare.Store
def transact_with_lock(lock, fun), do: transaction(fn -> with_advisory_lock(lock, fun) end)
@impl Hoare.Store
def fetch(schema, id), do: if(record = get(schema, id), do: {:ok, record}, else: {:error, :not_found})
endThe record's schema supplies changeset/2, which update/1 receives with the
new status. In tests a module that keeps records in memory is enough.
Summary
Callbacks
Runs fun inside a transaction that no other holder of lock shares; its result is the return.
Types
Callbacks
Runs fun inside a transaction that no other holder of lock shares; its result is the return.