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 update_config(
&self,
max_concurrent: usize,
rate_limit_per_minute: u32,
zombie_timeout_secs: u64,
)
pub fn update_config( &self, max_concurrent: usize, rate_limit_per_minute: u32, zombie_timeout_secs: u64, )
Hot-reload scheduler config without restart.
Updates concurrency limit, rate limit, and zombie timeout.
Takes effect on the next next_task() / reap_zombies() call.
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).