OzMcp.Tasks.EtsStore (OzMcp v0.9.0)

Copy Markdown View Source

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.

Summary

Functions

The records with the status :working or :input_required.

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

Removes the record.

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

Returns {:ok, record} or :not_found.

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

Writes the record.

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

Types

result()

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

status()

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

t()

@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
}

Functions

active(instance)

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

The records with the status :working or :input_required.

deadline_ms(map)

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

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

delete(instance, record)

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

Removes the record.

expired?(record, now \\ DateTime.utc_now())

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

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

get(instance, task_id)

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

Returns {:ok, record} or :not_found.

init(instance)

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

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

put(instance, record)

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

Writes the record.

table(instance)

@spec table(atom()) :: atom()

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