From 01b787c6a95be5fea670fec35da481b6b81f0e30 Mon Sep 17 00:00:00 2001 From: Matthew Plant Date: Mon, 20 May 2024 16:33:17 -0400 Subject: [PATCH] Make data set downloader poll duration a setting --- mobile_verifier/src/boosting_oracles/data_sets.rs | 15 +++++++++------ mobile_verifier/src/settings.rs | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mobile_verifier/src/boosting_oracles/data_sets.rs b/mobile_verifier/src/boosting_oracles/data_sets.rs index 06e65ae7a..76eaec1a4 100644 --- a/mobile_verifier/src/boosting_oracles/data_sets.rs +++ b/mobile_verifier/src/boosting_oracles/data_sets.rs @@ -2,9 +2,10 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, pin::pin, + time::Duration, }; -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Utc}; use file_store::{ file_sink::{self, FileSinkClient}, file_upload::FileUpload, @@ -112,6 +113,7 @@ pub struct DataSetDownloaderDaemon { oracle_boosting_sink: FileSinkClient, data_set_directory: PathBuf, new_coverage_object_notification: NewCoverageObjectNotification, + poll_duration: Duration, } #[derive(FromRow)] @@ -189,7 +191,7 @@ impl DataSetDownloaderDaemon { concat!(env!("CARGO_PKG_NAME"), "_oracle_boosting_report"), ) .auto_commit(true) - .roll_time(Duration::minutes(15)) + .roll_time(chrono::Duration::minutes(15)) .create() .await?; @@ -209,6 +211,7 @@ impl DataSetDownloaderDaemon { oracle_boosting_reports, settings.data_sets_directory.clone(), new_coverage_object_notification, + settings.data_sets_poll_duration, ); Ok(TaskManager::builder() @@ -231,6 +234,7 @@ where oracle_boosting_sink: FileSinkClient, data_set_directory: PathBuf, new_coverage_object_notification: NewCoverageObjectNotification, + poll_duration: Duration, ) -> Self { Self { pool, @@ -239,6 +243,7 @@ where oracle_boosting_sink, data_set_directory, new_coverage_object_notification, + poll_duration, } } @@ -306,8 +311,6 @@ where } pub async fn run(mut self) -> anyhow::Result<()> { - let poll_duration = Duration::minutes(1); - self.data_sets .urbanization .fetch_first_data_set(&self.pool, &self.data_set_directory) @@ -332,7 +335,7 @@ where .await?; } - let mut wakeup = Instant::now() + poll_duration.to_std()?; + let mut wakeup = Instant::now() + self.poll_duration; loop { #[rustfmt::skip] tokio::select! { @@ -349,7 +352,7 @@ where }, _ = tokio::time::sleep_until(wakeup) => { self.check_for_new_data_sets().await?; - wakeup = Instant::now() + poll_duration.to_std()?; + wakeup = Instant::now() + self.poll_duration; } } } diff --git a/mobile_verifier/src/settings.rs b/mobile_verifier/src/settings.rs index 744ca7fbb..4a5c681b5 100644 --- a/mobile_verifier/src/settings.rs +++ b/mobile_verifier/src/settings.rs @@ -46,6 +46,9 @@ pub struct Settings { pub max_asserted_distance_deviation: u32, /// Directory in which new oracle boosting data sets are downloaded into pub data_sets_directory: PathBuf, + /// Poll duration for new data sets + #[serde(with = "humantime_serde", default = "default_data_sets_poll_duration")] + pub data_sets_poll_duration: Duration, // Geofencing settings pub usa_and_mexico_geofence_regions: String, #[serde(default = "default_fencing_resolution")] @@ -84,6 +87,10 @@ fn default_reward_period_offset() -> Duration { humantime::parse_duration("30 minutes").unwrap() } +fn default_data_sets_poll_duration() -> Duration { + humantime::parse_duration("30 minutes").unwrap() +} + impl Settings { /// Load Settings from a given path. Settings are loaded from a given /// optional path and can be overriden with environment variables.