pub struct WorkerPool { /* private fields */ }Expand description
Pool of connected workers with capacity-aware task routing.
Implementations§
Source§impl WorkerPool
impl WorkerPool
pub fn new(heartbeat_timeout_ms: u64) -> Self
pub fn with_limits( heartbeat_timeout_ms: u64, max_pool_size: Option<u32>, min_pool_size: Option<u32>, on_pool_below_min: Option<Arc<dyn Fn(u32) + Send + Sync>>, ) -> Self
Sourcepub fn register(&self, info: WorkerInfo)
pub fn register(&self, info: WorkerInfo)
Register a worker. If the pool is at max capacity (and this is not a
re-registration of an existing worker), the registration is silently rejected.
Use try_register for explicit error handling.
Sourcepub fn try_register(&self, info: WorkerInfo) -> Result<(), PoolError>
pub fn try_register(&self, info: WorkerInfo) -> Result<(), PoolError>
Register a worker, returning an error if the pool is at max capacity. Re-registration of an existing worker (same ID) always succeeds (updates in place).
pub fn deregister(&self, worker_id: &str)
pub fn heartbeat(&self, worker_id: &str, active_tasks: u32)
Sourcepub fn select_and_reserve(&self, task_type: &str) -> Option<String>
pub fn select_and_reserve(&self, task_type: &str) -> Option<String>
Atomically selects a worker and reserves capacity. Returns the worker ID if one is available, or None. This avoids the TOCTOU race between select and dispatch.
Sourcepub fn select_worker(&self, task_type: &str) -> Option<String>
pub fn select_worker(&self, task_type: &str) -> Option<String>
Selects the least-loaded worker for a task type WITHOUT modifying state.
Use select_and_reserve for dispatch to avoid TOCTOU races.
pub fn mark_task_dispatched(&self, worker_id: &str)
pub fn mark_task_completed(&self, worker_id: &str)
pub fn detect_dead_workers(&self) -> Vec<String>
pub fn active_workers(&self) -> Vec<WorkerInfo>
pub fn count(&self) -> usize
pub fn stats(&self) -> PoolStats
Sourcepub fn workers(&self) -> Vec<WorkerInfo>
pub fn workers(&self) -> Vec<WorkerInfo>
List all connected workers with their full info.
Sourcepub fn drain_worker(&self, worker_id: &str) -> Result<(), PoolError>
pub fn drain_worker(&self, worker_id: &str) -> Result<(), PoolError>
Set a worker’s status to Draining so no new tasks are routed to it. Existing tasks will finish normally.
Sourcepub fn remove_worker(&self, worker_id: &str) -> Result<(), PoolError>
pub fn remove_worker(&self, worker_id: &str) -> Result<(), PoolError>
Force-remove a worker from the pool. Returns the list of pending task IDs that were assigned to this worker (caller is responsible for failing them).