SquidMesh.AttemptStore (squid_mesh v0.1.0-alpha.3)

Copy Markdown View Source

Durable store for step-attempt history.

Attempts are recorded separately from step runs so retry policy and observability can reason about attempt numbers, failure history, and the latest known attempt state.

Summary

Functions

Returns how many attempts have been recorded for a step run.

Allocates the next attempt number for a step run and persists it as running.

Marks one attempt as completed.

Marks one attempt as failed and stores the normalized error payload.

Returns the latest recorded attempt for a step run.

Returns the next available attempt number for a step run.

Records one step attempt with optional failure details.

Types

attempt_attrs()

@type attempt_attrs() :: %{optional(:error) => map() | nil}

stale_error()

@type stale_error() :: {:stale_attempt, String.t()}

Functions

attempt_count(repo, step_run_id)

@spec attempt_count(module(), Ecto.UUID.t()) :: non_neg_integer()

Returns how many attempts have been recorded for a step run.

begin_attempt(repo, step_run_id)

@spec begin_attempt(module(), Ecto.UUID.t()) ::
  {:ok, SquidMesh.Persistence.StepAttempt.t()} | {:error, Ecto.Changeset.t()}

Allocates the next attempt number for a step run and persists it as running.

complete_attempt(repo, attempt_id)

@spec complete_attempt(module(), Ecto.UUID.t()) ::
  {:ok, SquidMesh.Persistence.StepAttempt.t()}
  | {:error, :not_found | stale_error()}

Marks one attempt as completed.

fail_attempt(repo, attempt_id, error)

@spec fail_attempt(module(), Ecto.UUID.t(), map()) ::
  {:ok, SquidMesh.Persistence.StepAttempt.t()}
  | {:error, :not_found | stale_error()}

Marks one attempt as failed and stores the normalized error payload.

latest_attempt(repo, step_run_id)

@spec latest_attempt(module(), Ecto.UUID.t()) ::
  SquidMesh.Persistence.StepAttempt.t() | nil

Returns the latest recorded attempt for a step run.

next_attempt_number(repo, step_run_id)

@spec next_attempt_number(module(), Ecto.UUID.t()) :: pos_integer()

Returns the next available attempt number for a step run.

record_attempt(repo, step_run_id, attempt_number, status, attrs \\ %{})

@spec record_attempt(
  module(),
  Ecto.UUID.t(),
  pos_integer(),
  String.t(),
  attempt_attrs()
) ::
  {:ok, SquidMesh.Persistence.StepAttempt.t()} | {:error, Ecto.Changeset.t()}

Records one step attempt with optional failure details.