Implement Coordinator
This commit is contained in:
parent
04212dff1c
commit
28de8b1cc1
2 changed files with 28 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
|||
mod coordinator;
|
||||
|
||||
use tracing::error;
|
||||
|
||||
use crate::config::Config;
|
||||
|
|
|
|||
26
src/runner/coordinator.rs
Normal file
26
src/runner/coordinator.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue