fix: run_id = hash(monitor_id, interval_bucket) — unique per window, consistent across regions
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user