Skip to content

Commit

Permalink
feat: Throttle control loop
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Jan 21, 2024
1 parent 4036a78 commit ea3a37c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion coordinator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::time::Duration;

use tokio::time::sleep;
use tracing_subscriber::prelude::*;

use crate::block_streams_handler::BlockStreamsHandler;
Expand All @@ -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()
Expand Down Expand Up @@ -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(())
}
)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions coordinator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, Fut, T, E>(operation: F) -> Result<T, E>
where
Expand All @@ -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 {
Expand Down

0 comments on commit ea3a37c

Please sign in to comment.