pub struct TaskRegistry {
pub max_concurrent: usize,
pub viewable_window: usize,
pub task_timeout: Duration,
pub event_tx: DaemonEventSender,
/* 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().
task_timeout: DurationPer-task execution timeout.
event_tx: DaemonEventSenderEvent channel for dispatching task execution.
Implementations§
Source§impl TaskRegistry
impl TaskRegistry
Sourcepub fn new(
max_concurrent: usize,
viewable_window: usize,
task_timeout: Duration,
event_tx: DaemonEventSender,
) -> Self
pub fn new( max_concurrent: usize, viewable_window: usize, task_timeout: Duration, event_tx: DaemonEventSender, ) -> Self
Create a new registry with the given config and event sender.
Sourcepub fn create(
&mut self,
agent: CompactString,
description: String,
created_by: CompactString,
parent_id: Option<u64>,
status: TaskStatus,
spawned: bool,
) -> u64
pub fn create( &mut self, agent: CompactString, description: String, created_by: CompactString, parent_id: Option<u64>, status: TaskStatus, spawned: bool, ) -> u64
Create a new task and insert it into the registry.
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 watchers.
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.
Optionally filters by agent, status, or parent_id.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Count of currently InProgress tasks (not Blocked).
Sourcepub fn submit(
&mut self,
agent: CompactString,
message: String,
created_by: CompactString,
parent_id: Option<u64>,
registry: Arc<Mutex<TaskRegistry>>,
) -> (u64, TaskStatus)
pub fn submit( &mut self, agent: CompactString, message: String, created_by: CompactString, parent_id: Option<u64>, registry: Arc<Mutex<TaskRegistry>>, ) -> (u64, TaskStatus)
Submit a task for execution.
If under the concurrency limit, dispatches immediately and spawns a
watcher. Otherwise, queues the task. Returns (task_id, status).
Sourcepub fn complete(
&mut self,
task_id: u64,
result: Option<String>,
error: Option<String>,
registry: Arc<Mutex<TaskRegistry>>,
)
pub fn complete( &mut self, task_id: u64, result: Option<String>, error: Option<String>, registry: Arc<Mutex<TaskRegistry>>, )
Mark a task as Finished or Failed, then promote the next queued task.
Sourcepub fn promote_next(&mut self, registry: Arc<Mutex<TaskRegistry>>)
pub fn promote_next(&mut self, registry: Arc<Mutex<TaskRegistry>>)
Promote the next queued task to InProgress if a slot is available.
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, setting status to Blocked and storing the inbox item.
Returns a receiver that the tool call can await for the user’s 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 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.
Sourcepub fn queued_create_tasks(&self) -> BTreeMap<CompactString, Vec<(u64, String)>>
pub fn queued_create_tasks(&self) -> BTreeMap<CompactString, Vec<(u64, String)>>
Collect queued create_task entries grouped by agent.
Returns (agent, [(task_id, description)]) pairs, capped at
max_concurrent tasks per agent to avoid context overflow.