Continuum.Snapshot (continuum v0.5.0)

Copy Markdown View Source

Compacted history prefix for long-running workflows.

A snapshot does not capture a BEAM continuation. Workflow code still runs from the top; the snapshot only replaces an old prefix of raw journal events with compacted steps that validate the requested effect and return the previously journaled result.

Summary

Functions

Compact a contiguous event list into snapshot steps.

Decode a stored snapshot payload.

Encode a snapshot for storage.

Return the encoded size in bytes.

Current snapshot payload format version.

Types

step()

@type step() :: %{
  effect_type: atom(),
  command_id: term(),
  shape: term(),
  result: term(),
  advance_by: pos_integer()
}

t()

@type t() :: %Continuum.Snapshot{
  run_id: binary(),
  steps_by_seq: %{required(non_neg_integer()) => step()},
  taken_at: DateTime.t(),
  through_seq: non_neg_integer(),
  version_hash: binary()
}

Functions

compact(run_id, version_hash, events, opts \\ [])

@spec compact(binary(), binary(), [map()], keyword()) ::
  {:ok, t()} | {:skip, term()} | {:error, term()}

Compact a contiguous event list into snapshot steps.

Pass :base to extend an existing compatible snapshot. If the event list ends with a pending scheduled/awaited event, the compacted snapshot stops at the last complete step instead of covering the incomplete tail.

decode(binary)

@spec decode(binary()) :: t()

Decode a stored snapshot payload.

encode(snapshot)

@spec encode(t()) :: binary()

Encode a snapshot for storage.

encoded_size(snapshot)

@spec encoded_size(t()) :: non_neg_integer()

Return the encoded size in bytes.

format_version()

@spec format_version() :: pos_integer()

Current snapshot payload format version.