From 8c0b6548092c2cc3c4bdd4e4b056259cef160d1c Mon Sep 17 00:00:00 2001 From: Michael Jeffrey Date: Tue, 14 May 2024 10:28:44 -0700 Subject: [PATCH] Use std::time::Duration in file_info_poller std::Durations were being turned into chrono::Durations only to be turned right back into std::Durations. It also doesn't make much sense for the file poller to support negative time deltas, so we can remove that possibility. --- boost_manager/src/main.rs | 2 +- file_store/src/file_info_poller.rs | 13 +++++-------- iot_verifier/src/main.rs | 6 +++--- reward_index/src/main.rs | 6 ++---- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/boost_manager/src/main.rs b/boost_manager/src/main.rs index 56ad2ea8d..f3be11d49 100644 --- a/boost_manager/src/main.rs +++ b/boost_manager/src/main.rs @@ -85,7 +85,7 @@ impl Server { file_upload::FileUpload::from_settings_tm(&settings.output).await?; let store_base_path = path::Path::new(&settings.cache); - let reward_check_interval = chrono::Duration::from_std(settings.reward_check_interval)?; + let reward_check_interval = settings.reward_check_interval; // setup the received for the rewards manifest files let file_store = FileStore::from_settings(&settings.verifier).await?; diff --git a/file_store/src/file_info_poller.rs b/file_store/src/file_info_poller.rs index 112ebea72..a7bf6950a 100644 --- a/file_store/src/file_info_poller.rs +++ b/file_store/src/file_info_poller.rs @@ -1,11 +1,11 @@ use crate::{file_store, traits::MsgDecode, Error, FileInfo, FileStore, Result}; use aws_sdk_s3::types::ByteStream; -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Utc}; use derive_builder::Builder; use futures::{future::LocalBoxFuture, stream::BoxStream, StreamExt}; use futures_util::TryFutureExt; use retainer::Cache; -use std::{collections::VecDeque, marker::PhantomData, sync::Arc}; +use std::{collections::VecDeque, marker::PhantomData, sync::Arc, time::Duration}; use task_manager::ManagedTask; use tokio::sync::mpsc::{Receiver, Sender}; @@ -85,14 +85,14 @@ pub enum LookbackBehavior { #[derive(Debug, Clone, Builder)] #[builder(pattern = "owned")] pub struct FileInfoPollerConfig { - #[builder(default = "Duration::seconds(DEFAULT_POLL_DURATION_SECS)")] + #[builder(default = "DEFAULT_POLL_DURATION")] poll_duration: Duration, state: S, store: FileStore, prefix: String, parser: P, lookback: LookbackBehavior, - #[builder(default = "Duration::minutes(10)")] + #[builder(default = "Duration::from_secs(10 * 60)")] offset: Duration, #[builder(default = "5")] queue_size: usize, @@ -262,10 +262,7 @@ where } fn poll_duration(&self) -> std::time::Duration { - self.config - .poll_duration - .to_std() - .unwrap_or(DEFAULT_POLL_DURATION) + self.config.poll_duration } async fn is_already_processed(&self, file_info: &FileInfo) -> Result { diff --git a/iot_verifier/src/main.rs b/iot_verifier/src/main.rs index 6111722f3..4efcc15ed 100644 --- a/iot_verifier/src/main.rs +++ b/iot_verifier/src/main.rs @@ -149,9 +149,9 @@ impl Server { // * // setup entropy requirements // * - let max_lookback_age = chrono::Duration::from_std(settings.loader_window_max_lookback_age)?; + let max_lookback_age = settings.loader_window_max_lookback_age; let entropy_store = FileStore::from_settings(&settings.entropy).await?; - let entropy_interval = chrono::Duration::from_std(settings.entropy_interval)?; + let entropy_interval = settings.entropy_interval; let (entropy_loader_receiver, entropy_loader_server) = file_source::continuous_source::() .state(pool.clone()) @@ -184,7 +184,7 @@ impl Server { .await?; let packet_store = FileStore::from_settings(&settings.packet_ingest).await?; - let packet_interval = chrono::Duration::from_std(settings.packet_interval)?; + let packet_interval = settings.packet_interval; let (pk_loader_receiver, pk_loader_server) = file_source::continuous_source::() .state(pool.clone()) diff --git a/reward_index/src/main.rs b/reward_index/src/main.rs index 6b8bca704..600c6764f 100644 --- a/reward_index/src/main.rs +++ b/reward_index/src/main.rs @@ -75,15 +75,13 @@ impl Server { telemetry::initialize(&pool).await?; let file_store = FileStore::from_settings(&settings.verifier).await?; - let interval = chrono::Duration::from_std(settings.interval)?; - let (receiver, server) = file_source::continuous_source::() .state(pool.clone()) .store(file_store) .prefix(FileType::RewardManifest.to_string()) .lookback(LookbackBehavior::StartAfter(settings.start_after)) - .poll_duration(interval) - .offset(interval * 2) + .poll_duration(settings.interval) + .offset(settings.interval * 2) .create() .await?; let source_join_handle = server.start(shutdown_listener.clone()).await?;