Skip to content

Commit 9174209

Browse files
committed
Lock alarms when initializing
This means that online_status_workers wait before the alarms are initialized.
1 parent 4069171 commit 9174209

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "historyprovider"
33
description = "historyprovider-rs"
44
license = "MIT"
55
repository = "https://github.com/silicon-heaven/historyprovider-rs"
6-
version = "2.11.0"
6+
version = "2.11.1"
77
edition = "2024"
88

99
[profile.release]

src/sites.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ pub(crate) async fn sites_task(
553553
online_status_channels.insert(site.to_string(), tx);
554554
online_status_workers.push(online_status_worker(site.clone(), rx, client_cmd_tx.clone(), app_state.clone()));
555555
}
556+
557+
let alarms = &mut *app_state.alarms.write().await;
558+
let state_alarms = &mut *app_state.state_alarms.write().await;
559+
556560
online_status_task = Some(tokio::spawn(async move {
557561
debug!(target: "OnlineStatus", "online status task starts");
558562
futures::future::join_all(online_status_workers).await;
@@ -564,8 +568,7 @@ pub(crate) async fn sites_task(
564568
with_snapshot: true,
565569
..Default::default()
566570
};
567-
let mut alarms = BTreeMap::<String, Vec<AlarmWithTimestamp>>::new();
568-
let mut state_alarms = BTreeMap::<String, Vec<AlarmWithTimestamp>>::new();
571+
569572
for site_path in sites_info.keys() {
570573
if app_state.app_closing.load(std::sync::atomic::Ordering::Relaxed) {
571574
break;
@@ -592,13 +595,10 @@ pub(crate) async fn sites_task(
592595
}
593596
};
594597

595-
impl_update_alarms(&mut alarms, collect_alarms);
596-
impl_update_alarms(&mut state_alarms, collect_state_alarms);
598+
impl_update_alarms(alarms, collect_alarms);
599+
impl_update_alarms(state_alarms, collect_state_alarms);
597600
}
598601

599-
*app_state.alarms.write().await = alarms;
600-
*app_state.state_alarms.write().await = state_alarms;
601-
602602
periodic_sync_tx
603603
.unbounded_send(PeriodicSyncCommand::Enable)
604604
.unwrap_or_else(|e| log::error!("Cannot send periodic sync enable command: {e}"));

0 commit comments

Comments
 (0)