From 12a99a28b15d88fa91c58ba904f06658e9130d18 Mon Sep 17 00:00:00 2001 From: LastExceed Date: Sat, 17 Feb 2024 20:20:28 +0100 Subject: [PATCH] default unknown masters to slaveless --- src/state/listener.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/state/listener.rs b/src/state/listener.rs index 26a5d8e..431d699 100644 --- a/src/state/listener.rs +++ b/src/state/listener.rs @@ -1,4 +1,4 @@ -use std::ops::Sub; +use std::{collections::HashSet, ops::Sub}; use std::time::{Duration, Instant}; use boolinator::Boolinator; @@ -133,13 +133,16 @@ impl State { pub async fn update_slaves(&mut self, master: &String, short_slaves: bool, long_slaves: bool, power: bool) -> Result<(), &'static str> { dark_grey_ln!("updating slaves..."); + + let fallback = HashSet::new(); + let slaves_used_by_others = self .bookings .read() .await .iter() .filter(|(other, booking)| *other != master && booking.is_running()) - .flat_map(|(machine, _)| &SLAVES_BY_MASTER[machine]) //todo: error handing + .flat_map(|(machine, _)| SLAVES_BY_MASTER.get(machine).unwrap_or(&fallback)) //machine being unknown already got logged when it got turned on, so we can ignore it here .cloned() .collect();