pub struct TaskRuntime { /* private fields */ }Expand description
Bridges task storage with runtime execution state.
Owns both:
- A
TaskStoragebackend (durable, serializable) - A
TaskExecutorfor running task work and managing cancellation
Lives in turul-mcp-server (not in turul-mcp-task-storage) because it combines
backend-agnostic storage with executor-specific runtime primitives.
Implementations§
Source§impl TaskRuntime
impl TaskRuntime
Sourcepub fn new(
storage: Arc<dyn TaskStorage>,
executor: Arc<dyn TaskExecutor>,
) -> Self
pub fn new( storage: Arc<dyn TaskStorage>, executor: Arc<dyn TaskExecutor>, ) -> Self
Create a new task runtime with the given storage backend and executor.
Sourcepub fn with_default_executor(storage: Arc<dyn TaskStorage>) -> Self
pub fn with_default_executor(storage: Arc<dyn TaskStorage>) -> Self
Create a new task runtime with the given storage and the default TokioTaskExecutor.
Sourcepub fn with_recovery_timeout(self, timeout_ms: u64) -> Self
pub fn with_recovery_timeout(self, timeout_ms: u64) -> Self
Create with custom recovery timeout.
Sourcepub fn in_memory() -> Self
pub fn in_memory() -> Self
Create a new task runtime with in-memory storage and the default TokioTaskExecutor.
Sourcepub fn storage(&self) -> &dyn TaskStorage
pub fn storage(&self) -> &dyn TaskStorage
Get a reference to the underlying storage.
Sourcepub fn storage_arc(&self) -> Arc<dyn TaskStorage>
pub fn storage_arc(&self) -> Arc<dyn TaskStorage>
Get a shared reference to the storage Arc.
Sourcepub fn executor(&self) -> &dyn TaskExecutor
pub fn executor(&self) -> &dyn TaskExecutor
Get a reference to the executor.
Sourcepub async fn register_task(
&self,
task: TaskRecord,
) -> Result<TaskRecord, TaskStorageError>
pub async fn register_task( &self, task: TaskRecord, ) -> Result<TaskRecord, TaskStorageError>
Register a new task in storage. Returns the created record.
Does NOT start execution — call executor().start_task() separately
when the work is ready to run.
Sourcepub async fn update_status(
&self,
task_id: &str,
new_status: TaskStatus,
status_message: Option<String>,
) -> Result<TaskRecord, TaskStorageError>
pub async fn update_status( &self, task_id: &str, new_status: TaskStatus, status_message: Option<String>, ) -> Result<TaskRecord, TaskStorageError>
Update a task’s status in storage.
Sourcepub async fn complete_task(
&self,
task_id: &str,
outcome: TaskOutcome,
status: TaskStatus,
status_message: Option<String>,
) -> Result<(), TaskStorageError>
pub async fn complete_task( &self, task_id: &str, outcome: TaskOutcome, status: TaskStatus, status_message: Option<String>, ) -> Result<(), TaskStorageError>
Store a task’s result and update status atomically.
Sourcepub async fn cancel_task(
&self,
task_id: &str,
) -> Result<TaskRecord, TaskStorageError>
pub async fn cancel_task( &self, task_id: &str, ) -> Result<TaskRecord, TaskStorageError>
Cancel a task: delegate to executor AND update storage status.
Sourcepub async fn await_terminal(&self, task_id: &str) -> Option<TaskStatus>
pub async fn await_terminal(&self, task_id: &str) -> Option<TaskStatus>
Wait until a task reaches terminal status via the executor.
Returns None if the task is not tracked by the executor (already completed or not in-flight).
Sourcepub async fn get_task(
&self,
task_id: &str,
) -> Result<Option<TaskRecord>, TaskStorageError>
pub async fn get_task( &self, task_id: &str, ) -> Result<Option<TaskRecord>, TaskStorageError>
Get a task by ID from storage.
Sourcepub async fn get_task_result(
&self,
task_id: &str,
) -> Result<Option<TaskOutcome>, TaskStorageError>
pub async fn get_task_result( &self, task_id: &str, ) -> Result<Option<TaskOutcome>, TaskStorageError>
Get a task’s stored result.
Sourcepub async fn list_tasks(
&self,
cursor: Option<&str>,
limit: Option<u32>,
) -> Result<TaskListPage, TaskStorageError>
pub async fn list_tasks( &self, cursor: Option<&str>, limit: Option<u32>, ) -> Result<TaskListPage, TaskStorageError>
List tasks with pagination.
Sourcepub async fn list_tasks_for_session(
&self,
session_id: &str,
cursor: Option<&str>,
limit: Option<u32>,
) -> Result<TaskListPage, TaskStorageError>
pub async fn list_tasks_for_session( &self, session_id: &str, cursor: Option<&str>, limit: Option<u32>, ) -> Result<TaskListPage, TaskStorageError>
List tasks for a specific session.
Sourcepub async fn recover_stuck_tasks(&self) -> Result<Vec<String>, TaskStorageError>
pub async fn recover_stuck_tasks(&self) -> Result<Vec<String>, TaskStorageError>
Recover stuck tasks on startup. Called during server initialization.
Sourcepub async fn maintenance(&self) -> Result<(), TaskStorageError>
pub async fn maintenance(&self) -> Result<(), TaskStorageError>
Run periodic maintenance (TTL expiry, cleanup).
Auto Trait Implementations§
impl Freeze for TaskRuntime
impl !RefUnwindSafe for TaskRuntime
impl Send for TaskRuntime
impl Sync for TaskRuntime
impl Unpin for TaskRuntime
impl UnsafeUnpin for TaskRuntime
impl !UnwindSafe for TaskRuntime
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
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