From c753c866be79e7ae1ca03fc91c888e3f52d284e3 Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:02:31 +0530 Subject: [PATCH] fix: make the duration optional --- .../fuel_da_source_adapter.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_da_source_adapter.rs b/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_da_source_adapter.rs index 2a34957b762..38cc9b4d322 100644 --- a/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_da_source_adapter.rs +++ b/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_da_source_adapter.rs @@ -22,6 +22,8 @@ pub mod block_committer_ingestor; pub mod dummy_ingestor; mod service; +const POLLING_INTERVAL_MS: u64 = 10_000; + // Exists to help merge the ServiceRunner and DaCommitSource traits into one type impl pub struct FuelDaSourceService( ServiceRunner>, @@ -67,8 +69,11 @@ impl FuelDaSourceService where T: DaMetadataGetter + Send + Sync, { - pub fn new(ingestor: T, polling_interval: Duration) -> anyhow::Result { - let service = DaSourceService::new(ingestor, polling_interval); + pub fn new(ingestor: T, polling_interval: Option) -> anyhow::Result { + let service = DaSourceService::new( + ingestor, + polling_interval.unwrap_or(Duration::from_millis(POLLING_INTERVAL_MS)), + ); let service_runner = ServiceRunner::new(service); Ok(Self(service_runner)) } @@ -101,7 +106,8 @@ mod tests { async fn test_service_sets_cache_when_request_succeeds() { // given let mut service = - FuelDaSourceService::new(DummyIngestor, Duration::from_millis(1)).unwrap(); + FuelDaSourceService::new(DummyIngestor, Some(Duration::from_millis(1))) + .unwrap(); // when service.start().unwrap(); @@ -117,7 +123,8 @@ mod tests { async fn test_service_invalidates_cache() { // given let mut service = - FuelDaSourceService::new(DummyIngestor, Duration::from_millis(1)).unwrap(); + FuelDaSourceService::new(DummyIngestor, Some(Duration::from_millis(1))) + .unwrap(); // when service.start().unwrap(); @@ -135,7 +142,7 @@ mod tests { // given let mut service = FuelDaSourceService::new( FakeErroringMetadataIngestor, - Duration::from_millis(1), + Some(Duration::from_millis(1)), ) .unwrap();