# `OzMcp.Tasks.EtsStore`
[🔗](https://github.com/oz-elixir/oz_mcp/blob/v0.9.0/lib/oz_mcp/tasks/ets_store.ex#L1)

ETS record store of the tasks of one instance: the default store of
the option `:task_store` and it implements
`OzMcp.Tasks.StoreBehaviour`. One named table per instance (the
records table, `table/1`). The index of the records lives in
OzMcp.Tasks.Index: this store implements none of the optional
callbacks of the contract, so the facade OzMcp.Tasks.Records keeps
that index for it.

A separate owner process (OzMcp.Tasks.Table) calls `init/1` and owns
the tables. The tables are `:public`: the process of a task writes its
own record and the request processes read the records. A crash of
the owner deletes the records of the instance.

Hazard: the record keeps a snapshot of the principal that created the
task (`principal`), because the runner runs after the request ends, so
the check of the token cannot be replayed. It never holds the raw
token.

# `result`

```elixir
@type result() ::
  {:ok, map()}
  | {:error, %{code: integer(), message: String.t(), data: term()}}
  | nil
```

# `status`

```elixir
@type status() :: OzMcp.Structs.Task.status()
```

# `t`

```elixir
@type t() :: %OzMcp.Tasks.EtsStore{
  bytes: non_neg_integer(),
  client_capabilities: map(),
  created_at: DateTime.t(),
  expires_at_ms: integer() | nil,
  last_updated_at: DateTime.t(),
  owner_key: term(),
  pid: pid() | nil,
  poll_interval: non_neg_integer() | nil,
  principal: OzMcp.Auth.Principal.t() | nil,
  progress_token: String.t() | integer() | nil,
  required_scopes: [String.t()] | nil,
  result: result(),
  runner_pid: pid() | nil,
  seq: non_neg_integer(),
  session_id: String.t(),
  status: status(),
  status_message: String.t() | nil,
  task_id: String.t(),
  tool: {module(), String.t()},
  ttl: non_neg_integer() | nil
}
```

# `active`

```elixir
@spec active(atom()) :: [t()]
```

The records with the status `:working` or `:input_required`.

# `deadline_ms`

```elixir
@spec deadline_ms(t()) :: integer() | nil
```

Returns the deadline of the record in Unix milliseconds, or `nil`.

# `delete`

```elixir
@spec delete(atom(), t()) :: :ok
```

Removes the record.

# `expired?`

```elixir
@spec expired?(t(), DateTime.t()) :: boolean()
```

Returns true when the record ttl (ms from creation) has elapsed.

# `get`

```elixir
@spec get(atom(), String.t()) :: {:ok, t()} | :not_found
```

Returns `{:ok, record}` or `:not_found`.

# `init`

```elixir
@spec init(atom()) :: :ok
```

Creates the named ETS table of the records for the given instance.

# `put`

```elixir
@spec put(atom(), t()) :: :ok
```

Writes the record.

# `table`

```elixir
@spec table(atom()) :: atom()
```

Returns the name of the records table for the given instance.

---

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