Implement Coordinator

This commit is contained in:
Joscha 2023-08-09 14:57:31 +02:00
parent 04212dff1c
commit 28de8b1cc1
2 changed files with 28 additions and 0 deletions

View file

@ -1,3 +1,5 @@
mod coordinator;
use tracing::error;
use crate::config::Config;

26
src/runner/coordinator.rs Normal file
View file

@ -0,0 +1,26 @@
//! Coordinate performing runs across servers.
pub struct Coordinator {
names: Vec<String>,
current: usize,
}
impl Coordinator {
pub fn new(mut names: Vec<String>) -> 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();
}
}
}