From 91584333dd35de62c4e7df074929c8a8b6b395e3 Mon Sep 17 00:00:00 2001 From: jedarden Date: Sat, 23 May 2026 07:59:37 -0400 Subject: [PATCH] Fix parse_schedule_interval to handle unit attached to number The function was incorrectly splitting on whitespace, which failed for inputs like "every 6h" where the unit is directly attached to the number. Now it correctly parses by finding the first non-digit character. Fixes tests: - test_parse_schedule_interval_hours - test_parse_schedule_interval_minutes - test_parse_schedule_interval_seconds - test_parse_schedule_case_insensitive - test_worker_config_from_schedule Co-Authored-By: Claude Opus 4.7 --- .../rebalancer_worker/anti_entropy_worker.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/miroir-core/src/rebalancer_worker/anti_entropy_worker.rs b/crates/miroir-core/src/rebalancer_worker/anti_entropy_worker.rs index 60f0d7c..59e0d00 100644 --- a/crates/miroir-core/src/rebalancer_worker/anti_entropy_worker.rs +++ b/crates/miroir-core/src/rebalancer_worker/anti_entropy_worker.rs @@ -70,17 +70,30 @@ fn parse_schedule_interval(schedule: &str) -> Option { return None; } - let parts = schedule[6..].trim().split_whitespace().collect::>(); - if parts.is_empty() { + let rest = schedule[6..].trim(); + if rest.is_empty() { return None; } - let num_str = parts[0]; - let unit = parts.get(1).unwrap_or(&""); + // Find the first non-digit character to split number from unit + let mut num_end = 0; + for (i, c) in rest.chars().enumerate() { + if !c.is_ascii_digit() { + num_end = i; + break; + } + } + + if num_end == 0 { + return None; + } + + let num_str = &rest[..num_end]; + let unit = &rest[num_end..]; let value: u64 = num_str.parse().ok()?; - match *unit { + match unit { "s" | "sec" | "second" | "seconds" => Some(value), "m" | "min" | "minute" | "minutes" => Some(value * 60), "h" | "hour" | "hours" => Some(value * 3600),