ConduitMcp.Tasks.EtsStore (ConduitMCP v0.11.0)

Copy Markdown View Source

ETS-backed task store. Default implementation of ConduitMcp.Tasks.Store.

All state lives in the named ETS table :conduit_mcp_tasks. The table is owned by a long-lived ConduitMcp.EtsOwner process (ConduitMcp.Tasks.EtsStore.Owner) started from ConduitMcp.Application so the table outlives short-lived request processes — without this, a Bandit request handler that creates the table dies with it, and the next request sees an empty table. The table is :public so any process can read and write; concurrency is safe because each task id is the row key and rows are written atomically.

This store is in-memory only. Terminal-state rows accumulate until the BEAM restarts; pair it with ConduitMcp.Tasks.Janitor to evict them on an interval.

Summary

Functions

Cancels a task by setting status to "cancelled".

Removes terminal-state tasks (completed, failed, cancelled) older than ttl_ms. Tasks in working or input_required are never evicted. Returns the number of rows removed.

Creates a new task with the given id and metadata. Returns the stored task, or {:error, :task_limit_reached} when the configured row cap is hit.

Deletes a task. Returns :ok whether or not it existed.

Fetches a task by id.

Lists tasks matching opts, evaluated as a single :ets.select/3 match spec so filtering happens in the C layer and only matching rows are copied into the caller's heap.

Merges updates into the existing task. Returns the new task or {:error, :not_found}.

Functions

cancel(task_id)

Cancels a task by setting status to "cancelled".

cleanup(ttl_ms)

Removes terminal-state tasks (completed, failed, cancelled) older than ttl_ms. Tasks in working or input_required are never evicted. Returns the number of rows removed.

create(task_id, metadata \\ %{})

Creates a new task with the given id and metadata. Returns the stored task, or {:error, :task_limit_reached} when the configured row cap is hit.

The cap defaults to 10000 rows and is configurable via config :conduit_mcp, :tasks_max_rows. Terminal-state rows are reclaimed by ConduitMcp.Tasks.Janitor; working/input_required rows are not, so the cap is the backstop against unbounded growth.

delete(task_id)

Deletes a task. Returns :ok whether or not it existed.

get(task_id)

Fetches a task by id.

list(opts \\ [])

Lists tasks matching opts, evaluated as a single :ets.select/3 match spec so filtering happens in the C layer and only matching rows are copied into the caller's heap.

Options:

  • :owner — the caller's principal restricts to rows that principal may see: its own plus unowned ones, or only its own under :tasks_require_owner. nil = no principal: sees only unowned tasks; nothing under :tasks_require_owner (see ConduitMcp.Tasks.get/2). Pass :any (the default) for the unscoped listing.
  • :status — restrict to one task status.
  • :limit — maximum number of rows to return.

update(task_id, updates)

Merges updates into the existing task. Returns the new task or {:error, :not_found}.