pub struct TaskRegistry {
pub max_concurrent: usize,
pub viewable_window: usize,
/* private fields */
}Expand description
In-memory task registry with concurrency control.
Fields§
§max_concurrent: usizeMaximum number of concurrently InProgress tasks.
viewable_window: usizeMaximum number of tasks returned by list().
Implementations§
Source§impl TaskRegistry
impl TaskRegistry
Sourcepub fn new(max_concurrent: usize, viewable_window: usize) -> Self
pub fn new(max_concurrent: usize, viewable_window: usize) -> Self
Create a new registry with the given config.
Sourcepub fn create(
&mut self,
agent: CompactString,
description: String,
created_by: CompactString,
parent_id: Option<u64>,
status: TaskStatus,
) -> u64
pub fn create( &mut self, agent: CompactString, description: String, created_by: CompactString, parent_id: Option<u64>, status: TaskStatus, ) -> u64
Create a new task and insert it into the registry. Returns task ID.
Sourcepub fn get_mut(&mut self, id: u64) -> Option<&mut Task>
pub fn get_mut(&mut self, id: u64) -> Option<&mut Task>
Get a mutable reference to a task by ID.
Sourcepub fn set_status(&mut self, id: u64, status: TaskStatus)
pub fn set_status(&mut self, id: u64, status: TaskStatus)
Update task status and notify all watchers (watch + broadcast).
This is the single path for all status transitions.
Sourcepub fn list(
&self,
agent: Option<&str>,
status: Option<TaskStatus>,
parent_id: Option<Option<u64>>,
) -> Vec<&Task>
pub fn list( &self, agent: Option<&str>, status: Option<TaskStatus>, parent_id: Option<Option<u64>>, ) -> Vec<&Task>
List tasks, most recent first, up to viewable_window entries.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Count of currently InProgress tasks (not Blocked).
Sourcepub fn complete(
&mut self,
task_id: u64,
result: Option<String>,
error: Option<String>,
)
pub fn complete( &mut self, task_id: u64, result: Option<String>, error: Option<String>, )
Mark a task as Finished or Failed and broadcast a Completed event.
Sourcepub fn promote_next(&mut self) -> Option<(u64, CompactString, String)>
pub fn promote_next(&mut self) -> Option<(u64, CompactString, String)>
Find the next queued task and return its dispatch info, or None.
Sourcepub fn block(
&mut self,
task_id: u64,
question: String,
) -> Option<Receiver<String>>
pub fn block( &mut self, task_id: u64, question: String, ) -> Option<Receiver<String>>
Block a task for user approval. Returns a receiver for the response.
Sourcepub fn approve(&mut self, task_id: u64, response: String) -> bool
pub fn approve(&mut self, task_id: u64, response: String) -> bool
Approve a blocked task, sending the response and resuming execution.
Sourcepub fn kill(&mut self, task_id: u64) -> Option<AbortHandle>
pub fn kill(&mut self, task_id: u64) -> Option<AbortHandle>
Kill a running or blocked task. Returns abort handle if it had one.
Sourcepub fn subscribe_status(&self, task_id: u64) -> Option<Receiver<TaskStatus>>
pub fn subscribe_status(&self, task_id: u64) -> Option<Receiver<TaskStatus>>
Subscribe to a task’s status changes (for await_tasks).
Sourcepub fn find_by_session(&self, session_id: u64) -> Option<u64>
pub fn find_by_session(&self, session_id: u64) -> Option<u64>
Find a task by its session ID. Returns the task ID.
Sourcepub fn add_tokens(&mut self, task_id: u64, prompt: u64, completion: u64)
pub fn add_tokens(&mut self, task_id: u64, prompt: u64, completion: u64)
Add token usage to a task.