pub struct WorkerRegistry { /* private fields */ }Expand description
The worker registry — tracks all known workers and their status.
Implementations§
Source§impl WorkerRegistry
impl WorkerRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty registry with a 30-second heartbeat timeout — three missed beats at the workers’ 10-second cadence before a worker counts as dead.
Sourcepub fn with_heartbeat_timeout(self, secs: i64) -> Self
pub fn with_heartbeat_timeout(self, secs: i64) -> Self
Override the heartbeat timeout (builder-style). Tests use 0 to make everything instantly stale and 3600 to make nothing stale.
Sourcepub fn register(
&self,
id: impl Into<String>,
address: impl Into<String>,
capabilities: Capabilities,
)
pub fn register( &self, id: impl Into<String>, address: impl Into<String>, capabilities: Capabilities, )
Register a new worker or update an existing one.
Sourcepub fn heartbeat(&self, worker_id: &str, load: LoadMetrics)
pub fn heartbeat(&self, worker_id: &str, load: LoadMetrics)
Update a worker’s heartbeat and load metrics.
Sourcepub fn claim(&self, worker_id: &str, plan_id: impl Into<String>) -> bool
pub fn claim(&self, worker_id: &str, plan_id: impl Into<String>) -> bool
Record that plan_id has been placed on worker_id.
active_plans was initialised to vec![] and never touched again,
so has_capacity and the “least loaded” tie-break both compared
zeroes: placement picked an arbitrary worker and called it balanced.
Returns false if the worker is unknown.
Sourcepub fn release(&self, worker_id: &str, plan_id: &str) -> bool
pub fn release(&self, worker_id: &str, plan_id: &str) -> bool
Release a plan, whether it finished or failed.
Sourcepub fn disconnect(&self, worker_id: &str)
pub fn disconnect(&self, worker_id: &str)
Mark a worker as disconnected.
Sourcepub fn active_workers(&self) -> Vec<WorkerStatus>
pub fn active_workers(&self) -> Vec<WorkerStatus>
Get all alive, connected workers.
Sourcepub fn get(&self, worker_id: &str) -> Option<WorkerStatus>
pub fn get(&self, worker_id: &str) -> Option<WorkerStatus>
Get a specific worker by ID.
Sourcepub fn find_workers(
&self,
tags: &[String],
max_concurrent: usize,
) -> Vec<WorkerStatus>
pub fn find_workers( &self, tags: &[String], max_concurrent: usize, ) -> Vec<WorkerStatus>
Find workers matching required tags with available capacity.
Sourcepub fn total_count(&self) -> usize
pub fn total_count(&self) -> usize
Total number of registered workers (including disconnected).
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of alive, connected workers.
Sourcepub fn prune_stale(&self) -> Vec<WorkerId> ⓘ
pub fn prune_stale(&self) -> Vec<WorkerId> ⓘ
Drop workers that have stopped sending heartbeats.
The predicate was is_alive(timeout) || w.connected, and
is_alive already requires connected — so it reduced to
w.connected and pruned nothing that was still marked connected,
however long ago it had last been heard from. Which is the only
case worth pruning. It also had no callers.
Returns the ids that were dropped, so a caller can log them.
Trait Implementations§
Source§impl Clone for WorkerRegistry
impl Clone for WorkerRegistry
Source§fn clone(&self) -> WorkerRegistry
fn clone(&self) -> WorkerRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WorkerRegistry
impl Debug for WorkerRegistry
Auto Trait Implementations§
impl Freeze for WorkerRegistry
impl RefUnwindSafe for WorkerRegistry
impl Send for WorkerRegistry
impl Sync for WorkerRegistry
impl Unpin for WorkerRegistry
impl UnsafeUnpin for WorkerRegistry
impl UnwindSafe for WorkerRegistry
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more