FastestMCP.TaskBackend behaviour (fastest_mcp v0.2.0)

Copy Markdown View Source

Behaviour for background-task storage backends.

FastestMCP keeps task execution orchestration in FastestMCP.BackgroundTaskStore and delegates storage concerns to a backend. The split is intentional:

BackgroundTaskStore
-> owns process coordination, waiters, and EventBus emission
-> asks TaskBackend to persist, fetch, paginate, and expire task state

That keeps the current OTP runtime simple while making room for ETS-backed or distributed implementations without changing the public task API.

Summary

Types

list_result()

@type list_result() :: %{tasks: [task()], next_cursor: String.t() | nil}

store_ref()

@type store_ref() :: pid() | atom()

task()

@type task() :: map()

Callbacks

delete_task(store, task_id)

@callback delete_task(store :: store_ref(), task_id :: String.t()) ::
  :ok | {:error, term()}

expire_tasks(store, now_ms)

@callback expire_tasks(store :: store_ref(), now_ms :: integer()) ::
  {:ok, [String.t()]} | {:error, term()}

fetch_task(store, task_id, opts)

@callback fetch_task(store :: store_ref(), task_id :: String.t(), opts :: keyword()) ::
  {:ok, task()} | {:error, :not_found | term()}

list_tasks(store, opts)

@callback list_tasks(store :: store_ref(), opts :: keyword()) ::
  {:ok, list_result()} | {:error, term()}

put_task(store, task)

@callback put_task(store :: store_ref(), task()) :: :ok | {:error, term()}

start_link(opts)

@callback start_link(opts :: keyword()) :: GenServer.on_start()