fix: run_id = hash(monitor_id, interval_bucket) — unique per window, consistent across regions

This commit is contained in:
M1
2026-03-18 17:03:17 +04:00
parent b6a66ddb21
commit 7b98ae78e5
2 changed files with 10 additions and 4 deletions
+8 -2
View File
@@ -53,14 +53,20 @@ pub async fn fetch_and_run(
let coordinator_url = coordinator_url.to_string();
let token = token.to_string();
let region_owned = region.to_string();
// Derive run_id from the monitor's scheduled_at bucket
// Derive run_id by hashing (monitor_id, interval_bucket) so every region
// checking within the same scheduled window gets the same short ID.
let run_id_owned = {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let epoch = monitor.scheduled_at.as_deref()
.and_then(|s| chrono::DateTime::parse_from_rfc3339(s).ok())
.map(|dt| dt.timestamp())
.unwrap_or_else(|| chrono::Utc::now().timestamp());
let bucket = epoch / monitor.interval_s;
format!("{}:{}", &monitor.id[..8.min(monitor.id.len())], bucket)
let mut h = DefaultHasher::new();
monitor.id.hash(&mut h);
bucket.hash(&mut h);
format!("{:016x}", h.finish())
};
let in_flight = in_flight.clone();
tokio::spawn(async move {