pub struct TaskManager { /* private fields */ }Expand description
Centralized task lifecycle manager
Implementations§
Source§impl TaskManager
impl TaskManager
Sourcepub fn progress(
&self,
task_id: TaskId,
message: impl Into<String>,
) -> Result<(), TaskManagerError>
pub fn progress( &self, task_id: TaskId, message: impl Into<String>, ) -> Result<(), TaskManagerError>
Update task progress
Sourcepub fn complete(
&self,
task_id: TaskId,
output: Option<Value>,
) -> Result<(), TaskManagerError>
pub fn complete( &self, task_id: TaskId, output: Option<Value>, ) -> Result<(), TaskManagerError>
Complete a task with result
Sourcepub fn fail(
&self,
task_id: TaskId,
error: impl Into<String>,
) -> Result<(), TaskManagerError>
pub fn fail( &self, task_id: TaskId, error: impl Into<String>, ) -> Result<(), TaskManagerError>
Fail a task with error
Sourcepub fn get_result(&self, task_id: TaskId) -> Option<TaskResult>
pub fn get_result(&self, task_id: TaskId) -> Option<TaskResult>
Get task result
Sourcepub fn is_terminal(&self, task_id: TaskId) -> bool
pub fn is_terminal(&self, task_id: TaskId) -> bool
Check if task is terminal
Sourcepub fn subscribe(&self, task_id: TaskId) -> Option<Receiver<TaskEvent>>
pub fn subscribe(&self, task_id: TaskId) -> Option<Receiver<TaskEvent>>
Subscribe to task events
Returns a receiver that will receive all events for the task. The receiver is closed when the task completes.
Sourcepub fn subscribe_all(&self) -> Receiver<TaskEvent>
pub fn subscribe_all(&self) -> Receiver<TaskEvent>
Subscribe to all task events (global)
Sourcepub async fn wait(
&self,
task_id: TaskId,
) -> Result<TaskResult, TaskManagerError>
pub async fn wait( &self, task_id: TaskId, ) -> Result<TaskResult, TaskManagerError>
Wait for a task to complete
Returns the task result when the task completes.
Sourcepub fn add_child(
&self,
parent_id: TaskId,
child_id: TaskId,
) -> Result<(), TaskManagerError>
pub fn add_child( &self, parent_id: TaskId, child_id: TaskId, ) -> Result<(), TaskManagerError>
Add a child task to a parent
Sourcepub fn spawn_child(
&self,
parent_id: TaskId,
task: Task,
) -> Result<TaskId, TaskManagerError>
pub fn spawn_child( &self, parent_id: TaskId, task: Task, ) -> Result<TaskId, TaskManagerError>
Spawn a child task with the given parent ID, setting up parent-child relationship.
This is a convenience method that combines spawn + add_child in one call.
Sourcepub async fn wait_children(
&self,
parent_id: TaskId,
) -> Result<Vec<TaskResult>, TaskManagerError>
pub async fn wait_children( &self, parent_id: TaskId, ) -> Result<Vec<TaskResult>, TaskManagerError>
Wait for all child tasks of a parent to complete.
Returns a list of results for each child task.
Sourcepub fn get_children(
&self,
parent_id: TaskId,
) -> Result<Vec<TaskId>, TaskManagerError>
pub fn get_children( &self, parent_id: TaskId, ) -> Result<Vec<TaskId>, TaskManagerError>
Get all child task IDs for a parent task.
Sourcepub fn all_children_complete(&self, parent_id: TaskId) -> bool
pub fn all_children_complete(&self, parent_id: TaskId) -> bool
Check if all children of a parent task are complete.
Sourcepub fn pending_tasks(&self) -> Vec<TaskId>
pub fn pending_tasks(&self) -> Vec<TaskId>
Get pending task IDs (FIFO)
Sourcepub fn pop_pending(&self) -> Option<TaskId>
pub fn pop_pending(&self) -> Option<TaskId>
Pop the next pending task