pub struct AgentScheduler { /* private fields */ }Expand description
The agent scheduler.
Manages task queues, rate limiting, zombie detection, and priority scheduling. This is the central coordinator for all agent task execution.
Implementations§
Source§impl AgentScheduler
impl AgentScheduler
Sourcepub fn new(
max_concurrent: usize,
rate_limit_per_minute: u32,
zombie_timeout_secs: u64,
) -> Self
pub fn new( max_concurrent: usize, rate_limit_per_minute: u32, zombie_timeout_secs: u64, ) -> Self
Creates a new scheduler.
§Arguments
max_concurrent- Maximum number of tasks that can run simultaneouslyrate_limit_per_minute- Maximum LLM API calls per minutezombie_timeout_secs- How long before a running task is considered a zombie
Sourcepub fn set_budget_manager(&mut self, bm: Arc<BudgetManager>)
pub fn set_budget_manager(&mut self, bm: Arc<BudgetManager>)
Attaches a budget manager for scheduling checks.
When a budget manager is set, the scheduler will:
- Check
can_schedule()before starting a task (soft gate) - Track calls via
track_call()when a task begins
If no budget manager is set, tasks proceed normally.
Sourcepub fn submit(&self, task: ScheduledTask) -> Result<Uuid>
pub fn submit(&self, task: ScheduledTask) -> Result<Uuid>
Submits a task to the scheduler queue.
Returns the task ID on success.
Sourcepub fn next_task(&self) -> Option<ScheduledTask>
pub fn next_task(&self) -> Option<ScheduledTask>
Gets the next task ready for execution.
Returns None if:
- The queue is empty
- Max concurrent limit is reached
- Rate limit is exceeded
Sourcepub fn complete_task(&self, task_id: Uuid) -> Result<()>
pub fn complete_task(&self, task_id: Uuid) -> Result<()>
Marks a task as completed.
Removes the task from the running map.
Sourcepub fn fail_task(&self, task_id: Uuid, error: &str) -> Result<()>
pub fn fail_task(&self, task_id: Uuid, error: &str) -> Result<()>
Marks a task as failed with an error message.
Removes the task from the running map.
Sourcepub fn reap_zombies(&self) -> Vec<Uuid>
pub fn reap_zombies(&self) -> Vec<Uuid>
Detects and reaps zombie tasks (running longer than the configured timeout).
Returns the IDs of tasks that were reaped.
Sourcepub fn start_task(&self, task_id: Uuid) -> Result<()>
pub fn start_task(&self, task_id: Uuid) -> Result<()>
Marks a task as running by task ID.
The task must be in the queue (status Queued). This is used by the orchestrator to atomically claim a submitted task before execution.
Sourcepub fn cancel_task(&self, task_id: Uuid) -> Result<()>
pub fn cancel_task(&self, task_id: Uuid) -> Result<()>
Cancels a queued task by ID.
Only works on tasks still in the queue (not yet running).
Sourcepub fn stats(&self) -> SchedulerStats
pub fn stats(&self) -> SchedulerStats
Returns the current scheduler statistics.
Sourcepub fn rate_limit_remaining(&self) -> u32
pub fn rate_limit_remaining(&self) -> u32
Returns remaining rate limit capacity.
Sourcepub fn queued_tasks(&self) -> Vec<ScheduledTask>
pub fn queued_tasks(&self) -> Vec<ScheduledTask>
Returns all queued tasks (for debugging/monitoring).
Sourcepub fn running_tasks(&self) -> Vec<ScheduledTask>
pub fn running_tasks(&self) -> Vec<ScheduledTask>
Returns all running tasks (for debugging/monitoring).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AgentScheduler
impl !RefUnwindSafe for AgentScheduler
impl Send for AgentScheduler
impl Sync for AgentScheduler
impl Unpin for AgentScheduler
impl UnsafeUnpin for AgentScheduler
impl !UnwindSafe for AgentScheduler
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.