pub struct TaskManager { /* private fields */ }Expand description
Server-side task store and executor for the SEP-2663 Tasks extension.
Cheaply cloneable; all clones share the same state.
§Retention
Entries are swept opportunistically on every spawn / get_task /
update_task / cancel_task / running_task_count call: non-terminal
tasks whose ttl_ms has elapsed are marked failed (their operation is
aborted), and terminal tasks are evicted after being retained for one
further ttl_ms window past their terminal transition so pollers can
observe the final state.
Note that the retention window intentionally extends past the
creation-based lifetime that ttl_ms advertises on the wire: a task that
runs to its TTL deadline is marked failed around created + ttl_ms and
stays observable until roughly created + 2 × ttl_ms. This is compliant —
SEP-2663 lets servers delete expired tasks at any time after the TTL,
so retaining them longer as an observation grace period is a server-side
policy choice, not a wire-contract change. Clients may treat the task as
unusable after createdAt + ttlMs regardless.
Tasks with ttl_ms: None are retained for the lifetime of the manager
(spec: unlimited retention) — bound task creation or call
Self::shutdown yourself if you spawn such tasks in a long-lived
server. There is no background sweeper; an idle manager holds its entries
until the next call.
Implementations§
Source§impl TaskManager
impl TaskManager
pub fn new() -> TaskManager
Sourcepub fn spawn<F>(&self, options: TaskOptions, make_future: F) -> Taskwhere
F: FnOnce(TaskContext) -> Pin<Box<dyn Future<Output = Result<CallToolResult, TaskExit>> + Send>>,
pub fn spawn<F>(&self, options: TaskOptions, make_future: F) -> Taskwhere
F: FnOnce(TaskContext) -> Pin<Box<dyn Future<Output = Result<CallToolResult, TaskExit>> + Send>>,
Spawn an operation as a task and return its seed Task state for a
CreateTaskResult. The task is durably observable via
Self::get_task before this method returns.
make_future receives a TaskContext for mid-task input requests,
status messages, and cooperative cancellation checks.
Sourcepub fn get_task(&self, task_id: &str) -> Result<DetailedTask, ErrorData>
pub fn get_task(&self, task_id: &str) -> Result<DetailedTask, ErrorData>
Handle tasks/get: return the current DetailedTask state.
Sourcepub fn update_task(
&self,
task_id: &str,
input_responses: impl IntoIterator<Item = (String, Value)>,
) -> Result<(), ErrorData>
pub fn update_task( &self, task_id: &str, input_responses: impl IntoIterator<Item = (String, Value)>, ) -> Result<(), ErrorData>
Handle tasks/update: deliver inputResponses to the running
operation. Unknown, already-answered, or superseded keys are ignored
per spec; a partial set of responses is accepted.
Sourcepub fn cancel_task(&self, task_id: &str) -> Result<(), ErrorData>
pub fn cancel_task(&self, task_id: &str) -> Result<(), ErrorData>
Handle tasks/cancel: cooperative cancellation (SEP-2663).
Records the cancellation intent and acknowledges immediately, but
does not abort the underlying future or force a terminal state.
The operation observes cancellation via
TaskContext::is_cancel_requested / TaskContext::cancelled, or
via the error returned from a pending TaskContext::request_input
call (whose response channel is dropped here), and decides its own
terminal status:
- stops with
TaskExit::Cancelled→ recorded ascancelled, - stops with
TaskExit::Error→ recorded asfailedwith the error inlined (a real failure after a cancel request is not masked), - finishes its work anyway → recorded as
completed— per the spec, “the task may still reach a non-cancelledterminal status”.
Sourcepub fn running_task_count(&self) -> usize
pub fn running_task_count(&self) -> usize
Number of tasks currently in a non-terminal state.
Trait Implementations§
Source§impl Clone for TaskManager
impl Clone for TaskManager
Source§fn clone(&self) -> TaskManager
fn clone(&self) -> TaskManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for TaskManager
impl Default for TaskManager
Source§fn default() -> TaskManager
fn default() -> TaskManager
Auto Trait Implementations§
impl Freeze for TaskManager
impl RefUnwindSafe for TaskManager
impl Send for TaskManager
impl Sync for TaskManager
impl Unpin for TaskManager
impl UnsafeUnpin for TaskManager
impl UnwindSafe for TaskManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more