diff --git a/src/runner.rs b/src/runner.rs index 61f4bf9..18f8133 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -1,3 +1,5 @@ +mod coordinator; + use tracing::error; use crate::config::Config; diff --git a/src/runner/coordinator.rs b/src/runner/coordinator.rs new file mode 100644 index 0000000..316ce12 --- /dev/null +++ b/src/runner/coordinator.rs @@ -0,0 +1,26 @@ +//! Coordinate performing runs across servers. + +pub struct Coordinator { + names: Vec, + current: usize, +} + +impl Coordinator { + pub fn new(mut names: Vec) -> Self { + assert!(!names.is_empty()); + names.sort_unstable(); + Self { names, current: 0 } + } + + pub fn active(&self, name: &str) -> bool { + self.names[self.current] == name + } + + pub fn next(&mut self, name: &str) { + // Check just to prevent weird shenanigans + if self.active(name) { + self.current += 1; + self.current %= self.names.len(); + } + } +}