pub struct TaskManager { /* private fields */ }Expand description
Task manager
Manages the lifecycle of async tasks, including creation, status polling, progress updates, and result retrieval.
Implementations§
Source§impl TaskManager
impl TaskManager
Sourcepub fn with_base_uri(base_uri: impl Into<String>) -> Self
pub fn with_base_uri(base_uri: impl Into<String>) -> Self
Create a new task manager with a custom base URI
Sourcepub async fn create_task(&self, request: TaskRequest) -> Result<TaskHandle>
pub async fn create_task(&self, request: TaskRequest) -> Result<TaskHandle>
Create a new task
Returns a task handle immediately with the task in Queued state.
Sourcepub async fn get_task_status(&self, task_id: &TaskId) -> Result<TaskStatus>
pub async fn get_task_status(&self, task_id: &TaskId) -> Result<TaskStatus>
Get task status
Sourcepub async fn get_task_result(&self, task_id: &TaskId) -> Result<TaskResult>
pub async fn get_task_result(&self, task_id: &TaskId) -> Result<TaskResult>
Get task result
Returns an error if the task hasn’t completed yet.
Sourcepub async fn update_progress(
&self,
task_id: &TaskId,
progress: TaskProgress,
) -> Result<()>
pub async fn update_progress( &self, task_id: &TaskId, progress: TaskProgress, ) -> Result<()>
Update task progress
This should be called by the worker executing the task.
Sourcepub async fn mark_working(&self, task_id: &TaskId) -> Result<()>
pub async fn mark_working(&self, task_id: &TaskId) -> Result<()>
Mark task as working
Sourcepub async fn mark_completed(
&self,
task_id: &TaskId,
result: Value,
) -> Result<()>
pub async fn mark_completed( &self, task_id: &TaskId, result: Value, ) -> Result<()>
Mark task as completed with result
Sourcepub async fn mark_failed(
&self,
task_id: &TaskId,
error: impl Into<String>,
) -> Result<()>
pub async fn mark_failed( &self, task_id: &TaskId, error: impl Into<String>, ) -> Result<()>
Mark task as failed
Sourcepub async fn mark_cancelled(&self, task_id: &TaskId) -> Result<()>
pub async fn mark_cancelled(&self, task_id: &TaskId) -> Result<()>
Mark task as cancelled
Sourcepub async fn mark_input_required(&self, task_id: &TaskId) -> Result<()>
pub async fn mark_input_required(&self, task_id: &TaskId) -> Result<()>
Mark task as requiring input
Sourcepub async fn list_tasks(&self) -> Result<Vec<TaskStatus>>
pub async fn list_tasks(&self) -> Result<Vec<TaskStatus>>
List all tasks
Sourcepub async fn cancel_task(&self, task_id: &TaskId) -> Result<()>
pub async fn cancel_task(&self, task_id: &TaskId) -> Result<()>
Cancel a task
Returns an error if the task is already in a terminal state or doesn’t support cancellation.
Sourcepub async fn cleanup_old_tasks(&self, older_than: Duration) -> Result<usize>
pub async fn cleanup_old_tasks(&self, older_than: Duration) -> Result<usize>
Clean up old completed tasks
Removes tasks that completed before the given threshold.
Trait Implementations§
Source§impl Clone for TaskManager
impl Clone for TaskManager
Source§fn clone(&self) -> TaskManager
fn clone(&self) -> TaskManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TaskManager
impl !RefUnwindSafe for TaskManager
impl Send for TaskManager
impl Sync for TaskManager
impl Unpin 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
Mutably borrows from an owned value. Read more