pub struct WorkerRegistry { /* private fields */ }Expand description
Workers seen by the pick route within WORKER_SEEN_TTL.
Cheap to clone: clones share the same record.
§Examples
use ironflow_api::worker_registry::WorkerRegistry;
use ironflow_store::entities::WorkerCapabilities;
let registry = WorkerRegistry::new();
registry.record("worker-1", Some(WorkerCapabilities::new(None, vec!["gpu".to_string()])));
let routing = registry.routing_for("transcode", &["gpu".to_string()]);
assert_eq!(routing.seen_workers, 1);
assert_eq!(routing.eligible_workers, 1);Implementations§
Source§impl WorkerRegistry
impl WorkerRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty registry using WORKER_SEEN_TTL.
§Examples
use ironflow_api::worker_registry::WorkerRegistry;
let registry = WorkerRegistry::new();
assert_eq!(registry.routing_for("deploy", &[]).seen_workers, 0);Sourcepub fn with_ttl(ttl: Duration) -> Self
pub fn with_ttl(ttl: Duration) -> Self
Create an empty registry where a worker counts as seen for ttl.
§Examples
use std::time::Duration;
use ironflow_api::worker_registry::WorkerRegistry;
let registry = WorkerRegistry::with_ttl(Duration::from_secs(30));
registry.record("worker-1", None);
assert_eq!(registry.routing_for("deploy", &[]).seen_workers, 1);Sourcepub fn record(&self, worker_id: &str, capabilities: Option<WorkerCapabilities>)
pub fn record(&self, worker_id: &str, capabilities: Option<WorkerCapabilities>)
Record that worker_id asked for a run with these capabilities.
Replaces what was known about that worker, and drops the workers not seen within the TTL.
§Examples
use ironflow_api::worker_registry::WorkerRegistry;
let registry = WorkerRegistry::new();
registry.record("worker-1", None);
registry.record("worker-1", None);
assert_eq!(registry.routing_for("deploy", &[]).seen_workers, 1);Sourcepub fn routing_for(
&self,
workflow_name: &str,
required_tags: &[String],
) -> WorkerRouting
pub fn routing_for( &self, workflow_name: &str, required_tags: &[String], ) -> WorkerRouting
Count the workers seen within the TTL, and those that could take a run
of workflow_name requiring required_tags.
A worker without capabilities (an older release) can take any run.
§Examples
use ironflow_api::worker_registry::WorkerRegistry;
use ironflow_store::entities::WorkerCapabilities;
let registry = WorkerRegistry::new();
registry.record("cpu-1", Some(WorkerCapabilities::new(None, Vec::new())));
let routing = registry.routing_for("transcode", &["gpu".to_string()]);
assert_eq!(routing.seen_workers, 1);
assert_eq!(routing.eligible_workers, 0);Trait Implementations§
Source§impl Clone for WorkerRegistry
impl Clone for WorkerRegistry
Source§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
Mutably borrows from an owned value. Read more