Skip to main content

TaskRegistry

Struct TaskRegistry 

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

Maximum number of concurrently InProgress tasks.

§viewable_window: usize

Maximum number of tasks returned by list().

Implementations§

Source§

impl TaskRegistry

Source

pub fn new(max_concurrent: usize, viewable_window: usize) -> Self

Create a new registry with the given config.

Source

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

Subscribe to task lifecycle events.

Source

pub fn task_info(task: &Task) -> TaskInfo

Build a TaskInfo snapshot from an internal Task.

Source

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.

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 all watchers (watch + broadcast).

This is the single path for all status transitions.

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.

Source

pub fn active_count(&self) -> usize

Count of currently InProgress tasks (not Blocked).

Source

pub fn has_slot(&self) -> bool

Whether a new task can be dispatched immediately.

Source

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.

Source

pub fn promote_next(&mut self) -> Option<(u64, CompactString, String)>

Find the next queued task and return its dispatch info, or None.

Source

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.

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 kill(&mut self, task_id: u64) -> Option<AbortHandle>

Kill a running or blocked task. Returns abort handle if it had one.

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.

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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