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

Copy Markdown View Source

A versioned, JSON-safe description of restartable task work.

Work descriptors contain data only. The type selects an application-owned executor and the idempotency_key remains stable across claims, process restarts, and execution retries. The immutable retry policy is expanded to exact delays before persistence, so an in-flight task does not change policy when application configuration changes. Applications should use the stable key when making externally visible side effects idempotent.

Summary

Functions

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

Builds a validated application-defined work descriptor.

Builds a validated work descriptor or raises ArgumentError.

Returns the descriptor with a validated immutable retry policy.

Encodes a descriptor as a stable JSON-safe persistence map.

Builds the standard descriptor for a durable tools/call invocation.

Validates a descriptor constructed locally or decoded by an adapter.

Types

t()

@type t() :: %Snodo.Extensions.Tasks.Work{
  idempotency_key: String.t(),
  input: map(),
  retry_policy: Snodo.Extensions.Tasks.RetryPolicy.t(),
  type: String.t()
}

Functions

from_map(encoded)

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

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

new(idempotency_key, type, input, opts \\ [])

@spec new(String.t(), String.t(), map(), keyword()) :: {:ok, t()} | {:error, term()}

Builds a validated application-defined work descriptor.

new!(idempotency_key, type, input, opts \\ [])

@spec new!(String.t(), String.t(), map(), keyword()) :: t()

Builds a validated work descriptor or raises ArgumentError.

put_retry_policy(work, retry_policy)

@spec put_retry_policy(t(), Snodo.Extensions.Tasks.RetryPolicy.t()) ::
  {:ok, t()} | {:error, term()}

Returns the descriptor with a validated immutable retry policy.

to_map(work)

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

Encodes a descriptor as a stable JSON-safe persistence map.

tool_call(idempotency_key, tool_name, arguments, opts \\ [])

@spec tool_call(String.t(), String.t(), map(), keyword()) ::
  {:ok, t()} | {:error, term()}

Builds the standard descriptor for a durable tools/call invocation.

validate(work)

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

Validates a descriptor constructed locally or decoded by an adapter.