Docket.Run.TaskState (docket v0.1.0)

Copy Markdown View Source

Durable description of one node execution attempt.

Task state appears in event payloads, checkpoint metadata, and — while a superstep is parked between attempts — in Docket.Run.active_tasks. An active entry pins the activation identity for the next attempt: the stable task_id, the attempt number to execute, the committed state snapshot and source versions the superstep planned against, and every prior failed attempt. Re-executing from this state preserves the task and idempotency identity of the superstep that parked it.

Summary

Types

One durably recorded failed attempt: the attempt number and reason text.

t()

Functions

Builds the idempotency key for one attempt of a task.

Hashes a committed state snapshot into the activation's input identity.

Builds the stable task identity for one node execution in one superstep.

Types

failure()

@type failure() :: %{attempt: pos_integer(), reason: String.t()}

One durably recorded failed attempt: the attempt number and reason text.

t()

@type t() :: %Docket.Run.TaskState{
  attempt: pos_integer(),
  deadline_at: DateTime.t() | nil,
  failures: [failure()],
  idempotency_key: String.t() | nil,
  input_hash: String.t() | nil,
  metadata: map(),
  node_id: String.t(),
  snapshot: map() | nil,
  source_versions: %{optional(String.t()) => non_neg_integer()} | nil,
  started_at: DateTime.t() | nil,
  status: atom() | nil,
  step: non_neg_integer(),
  task_id: String.t()
}

Functions

idempotency_key(task_id, attempt)

@spec idempotency_key(String.t(), pos_integer()) :: String.t()

Builds the idempotency key for one attempt of a task.

snapshot_hash(snapshot)

@spec snapshot_hash(map()) :: String.t()

Hashes a committed state snapshot into the activation's input identity.

The hash is over deterministic external term format bytes, so equal durable snapshots hash equally regardless of map insertion order.

task_id(run_id, step, node_id)

@spec task_id(String.t(), non_neg_integer(), String.t()) :: String.t()

Builds the stable task identity for one node execution in one superstep.

The same committed run always yields the same task ID, so a superstep that never commits re-plans with byte-identical identities.