Snodo.Extensions.Tasks.Snapshot (snodo_tasks v0.2.0)

Copy Markdown View Source

A revisioned Task aggregate used at persistence and compare-and-set boundaries.

work, retry bookkeeping, input_history, and accepted_input_responses are private execution state and are never projected onto the Tasks wire shape. The original request for every lifetime-unique input key remains in input_history, allowing a recovered worker to distinguish an identical replay from an ambiguous key reuse. Accepted responses remain persisted when no local worker is available.

Summary

Functions

Decodes and validates a persistence map produced by to_map/1.

Creates the initial revision-zero snapshot for a durable Task.

Encodes the complete aggregate as a stable JSON-safe persistence map.

Types

retry_failure()

@type retry_failure() :: map()

t()

@type t() :: %Snodo.Extensions.Tasks.Snapshot{
  accepted_input_responses: %{optional(String.t()) => map()},
  input_history: %{optional(String.t()) => map()},
  last_failure: retry_failure() | nil,
  retry_at: String.t() | nil,
  retry_count: non_neg_integer(),
  revision: non_neg_integer(),
  task: Snodo.Extensions.Tasks.Task.t(),
  work: Snodo.Extensions.Tasks.Work.t() | nil
}

Functions

from_map(encoded)

@spec from_map(term()) :: {:ok, t()} | {:error, term()}

Decodes and validates a persistence map produced by to_map/1.

new(task, work \\ nil)

Creates the initial revision-zero snapshot for a durable Task.

to_map(snapshot)

@spec to_map(t()) :: map()

Encodes the complete aggregate as a stable JSON-safe persistence map.