# `Snodo.Extensions.Tasks.Work`
[🔗](https://github.com/joshrotenberg/snodo/blob/v0.2.0/extensions/tasks/lib/snodo/extensions/tasks/work.ex#L1)

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.

# `t`

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

# `from_map`

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

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

# `new`

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

Builds a validated application-defined work descriptor.

# `new!`

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

Builds a validated work descriptor or raises `ArgumentError`.

# `put_retry_policy`

```elixir
@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`

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

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

# `tool_call`

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

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

# `validate`

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

Validates a descriptor constructed locally or decoded by an adapter.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
