Skip to main content

TaskRegistry

Struct TaskRegistry 

Source
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: usize

Maximum number of concurrently InProgress tasks.

§viewable_window: usize

Maximum number of tasks returned by list().

§task_timeout: Duration

Per-task execution timeout.

§event_tx: DaemonEventSender

Event channel for dispatching task execution.

Implementations§

Source§

impl TaskRegistry

Source

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.

Source

pub fn subscribe(&self) -> Receiver<TaskEvent>

Subscribe to task lifecycle events.

Source

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.

Source

pub fn get(&self, id: u64) -> Option<&Task>

Get a reference to a task by ID.

Source

pub fn get_mut(&mut self, id: u64) -> Option<&mut Task>

Get a mutable reference to a task by ID.

Source

pub fn set_status(&mut self, id: u64, status: TaskStatus)

Update task status and notify watchers.

Source

pub fn remove(&mut self, id: u64) -> Option<Task>

Remove a task from the registry.

Source

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.

Source

pub fn active_count(&self) -> usize

Count of currently InProgress tasks (not Blocked).

Source

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).

Source

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.

Source

pub fn promote_next(&mut self, registry: Arc<Mutex<TaskRegistry>>)

Promote the next queued task to InProgress if a slot is available.

Source

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.

Source

pub fn approve(&mut self, task_id: u64, response: String) -> bool

Approve a blocked task, sending the response and resuming execution.

Source

pub fn subscribe_status(&self, task_id: u64) -> Option<Receiver<TaskStatus>>

Subscribe to a task’s status changes (for await_tasks).

Source

pub fn children(&self, parent_id: u64) -> Vec<&Task>

Get all child tasks of a given parent.

Source

pub fn find_by_session(&self, session_id: u64) -> Option<u64>

Find a task by its session ID. Returns the task ID.

Source

pub fn add_tokens(&mut self, task_id: u64, prompt: u64, completion: u64)

Add token usage to a task.

Source

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.

Source

pub fn queued_create_tasks_for(&self, agent: &str) -> Vec<(u64, String)>

Collect queued create_task entries for a single agent, capped at max_concurrent.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more