From ea3a37ca00708cf1a2cbfc4e91e9b37570d6a4ee Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 22 Jan 2024 09:06:46 +1300 Subject: [PATCH] feat: Throttle control loop --- coordinator/src/main.rs | 11 ++++++++++- coordinator/src/utils.rs | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/coordinator/src/main.rs b/coordinator/src/main.rs index 338e408fb..dd3cf0258 100644 --- a/coordinator/src/main.rs +++ b/coordinator/src/main.rs @@ -1,3 +1,6 @@ +use std::time::Duration; + +use tokio::time::sleep; use tracing_subscriber::prelude::*; use crate::block_streams_handler::BlockStreamsHandler; @@ -11,6 +14,8 @@ mod redis; mod registry; mod utils; +const CONTROL_LOOP_THROTTLE_SECONDS: Duration = Duration::from_secs(1); + #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::registry() @@ -38,7 +43,11 @@ async fn main() -> anyhow::Result<()> { tokio::try_join!( synchronise_executors(&indexer_registry, &executors_handler), - synchronise_block_streams(&indexer_registry, &redis_client, &block_streams_handler) + synchronise_block_streams(&indexer_registry, &redis_client, &block_streams_handler), + async { + sleep(CONTROL_LOOP_THROTTLE_SECONDS).await; + Ok(()) + } )?; } } diff --git a/coordinator/src/utils.rs b/coordinator/src/utils.rs index 696e0a0b4..cd4bf647d 100644 --- a/coordinator/src/utils.rs +++ b/coordinator/src/utils.rs @@ -2,7 +2,7 @@ use std::time::Duration; use futures_util::future::Future; -const INITIAL_DELAY_SECONDS: u64 = 1; +const INITIAL_DELAY_SECONDS: Duration = Duration::from_secs(1); pub async fn exponential_retry(operation: F) -> Result where @@ -11,7 +11,7 @@ where E: std::fmt::Debug, { let mut attempts = 1; - let mut delay = Duration::from_secs(INITIAL_DELAY_SECONDS); + let mut delay = INITIAL_DELAY_SECONDS; loop { match operation().await {