Skip to content

Commit

Permalink
Make data set downloader poll duration a setting
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed May 20, 2024
1 parent 6c65b8b commit 01b787c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mobile_verifier/src/boosting_oracles/data_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -112,6 +113,7 @@ pub struct DataSetDownloaderDaemon<A, B, C> {
oracle_boosting_sink: FileSinkClient,
data_set_directory: PathBuf,
new_coverage_object_notification: NewCoverageObjectNotification,
poll_duration: Duration,
}

#[derive(FromRow)]
Expand Down Expand Up @@ -189,7 +191,7 @@ impl DataSetDownloaderDaemon<Footfall, Landtype, Urbanization> {
concat!(env!("CARGO_PKG_NAME"), "_oracle_boosting_report"),
)
.auto_commit(true)
.roll_time(Duration::minutes(15))
.roll_time(chrono::Duration::minutes(15))
.create()
.await?;

Expand All @@ -209,6 +211,7 @@ impl DataSetDownloaderDaemon<Footfall, Landtype, Urbanization> {
oracle_boosting_reports,
settings.data_sets_directory.clone(),
new_coverage_object_notification,
settings.data_sets_poll_duration,
);

Ok(TaskManager::builder()
Expand All @@ -231,6 +234,7 @@ where
oracle_boosting_sink: FileSinkClient,
data_set_directory: PathBuf,
new_coverage_object_notification: NewCoverageObjectNotification,
poll_duration: Duration,
) -> Self {
Self {
pool,
Expand All @@ -239,6 +243,7 @@ where
oracle_boosting_sink,
data_set_directory,
new_coverage_object_notification,
poll_duration,
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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! {
Expand All @@ -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;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions mobile_verifier/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 01b787c

Please sign in to comment.