pub struct BackgroundTaskManager { /* private fields */ }Expand description
Thread-scoped background task manager.
Manages the full lifecycle: spawn → track → cancel → query. Tasks outlive individual runs but are scoped to a thread.
Implementations§
Source§impl BackgroundTaskManager
impl BackgroundTaskManager
pub fn new() -> Self
pub fn with_task_store(task_store: Option<Arc<TaskStore>>) -> Self
Sourcepub async fn spawn<F, Fut>(
&self,
owner_thread_id: &str,
task_type: &str,
description: &str,
task: F,
) -> TaskIdwhere
F: FnOnce(RunCancellationToken) -> Fut + Send + 'static,
Fut: Future<Output = TaskResult> + Send,
pub async fn spawn<F, Fut>(
&self,
owner_thread_id: &str,
task_type: &str,
description: &str,
task: F,
) -> TaskIdwhere
F: FnOnce(RunCancellationToken) -> Fut + Send + 'static,
Fut: Future<Output = TaskResult> + Send,
Spawn a background task with the given closure.
Returns the generated TaskId immediately. The closure receives a
CancellationToken for cooperative cancellation.
Sourcepub async fn spawn_with_id<F, Fut>(
&self,
params: SpawnParams,
cancel_token: RunCancellationToken,
task: F,
) -> TaskIdwhere
F: FnOnce(RunCancellationToken) -> Fut + Send + 'static,
Fut: Future<Output = TaskResult> + Send,
pub async fn spawn_with_id<F, Fut>(
&self,
params: SpawnParams,
cancel_token: RunCancellationToken,
task: F,
) -> TaskIdwhere
F: FnOnce(RunCancellationToken) -> Fut + Send + 'static,
Fut: Future<Output = TaskResult> + Send,
Spawn a background task with a caller-supplied ID and cancellation token.
Use this when the caller already owns an ID (e.g. a sub-agent run_id)
and/or a cancellation token that is shared with other subsystems.
Sourcepub async fn cancel(
&self,
owner_thread_id: &str,
task_id: &str,
) -> Result<(), String>
pub async fn cancel( &self, owner_thread_id: &str, task_id: &str, ) -> Result<(), String>
Cancel a task owned by the given thread. Returns true if cancelled.
Sourcepub async fn get(
&self,
owner_thread_id: &str,
task_id: &str,
) -> Option<TaskSummary>
pub async fn get( &self, owner_thread_id: &str, task_id: &str, ) -> Option<TaskSummary>
Get a summary of a single task.
Sourcepub async fn list(
&self,
owner_thread_id: &str,
status_filter: Option<TaskStatus>,
) -> Vec<TaskSummary>
pub async fn list( &self, owner_thread_id: &str, status_filter: Option<TaskStatus>, ) -> Vec<TaskSummary>
List all tasks for a thread, optionally filtered by status.
Sourcepub async fn has_running_tasks(&self, owner_thread_id: &str) -> bool
pub async fn has_running_tasks(&self, owner_thread_id: &str) -> bool
Check if there are running tasks for a thread.
Sourcepub async fn gc_terminal(&self, owner_thread_id: &str) -> usize
pub async fn gc_terminal(&self, owner_thread_id: &str) -> usize
Remove completed/terminal task entries from the in-memory table.
Sourcepub async fn contains(&self, owner_thread_id: &str, task_id: &str) -> bool
pub async fn contains(&self, owner_thread_id: &str, task_id: &str) -> bool
Check if a task exists for the given thread.
Sourcepub async fn contains_any(&self, task_id: &str) -> bool
pub async fn contains_any(&self, task_id: &str) -> bool
Check if a task exists in any thread.
Sourcepub async fn cancel_tree(
&self,
owner_thread_id: &str,
task_id: &str,
) -> Result<Vec<TaskSummary>, String>
pub async fn cancel_tree( &self, owner_thread_id: &str, task_id: &str, ) -> Result<Vec<TaskSummary>, String>
Cancel a task and all its descendants (by parent_task_id chain).
Returns summaries of all tasks that were cancelled. The root task must
be owned by owner_thread_id; descendants are found by traversing
parent_task_id links within the same owner.
Sourcepub async fn update_status(
&self,
task_id: &str,
status: TaskStatus,
error: Option<String>,
) -> bool
pub async fn update_status( &self, task_id: &str, status: TaskStatus, error: Option<String>, ) -> bool
Externally update a task’s status (e.g. recovery marking orphans as stopped).
Sourcepub async fn list_by_type(
&self,
owner_thread_id: &str,
task_type: &str,
status_filter: Option<TaskStatus>,
) -> Vec<TaskSummary>
pub async fn list_by_type( &self, owner_thread_id: &str, task_type: &str, status_filter: Option<TaskStatus>, ) -> Vec<TaskSummary>
List tasks filtered by task_type, optionally filtered by status.
Trait Implementations§
Source§impl Clone for BackgroundTaskManager
impl Clone for BackgroundTaskManager
Source§fn clone(&self) -> BackgroundTaskManager
fn clone(&self) -> BackgroundTaskManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more