Skip to content

Commit

Permalink
feat(torii): make poll time configurable (#2327)
Browse files Browse the repository at this point in the history
* default index pending & and make polling_interval configurable

* fix with recommandation

* back to 1s interval

* feat: default values for engine

---------

Co-authored-by: notV4l <[email protected]>
  • Loading branch information
Larkooo and notV4l authored Aug 21, 2024
1 parent 54a891e commit 4aa7454
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

use clap::Parser;
use clap::{ArgAction, Parser};
use common::parse::{parse_socket_address, parse_url};
use dojo_metrics::{metrics_process, prometheus_exporter};
use dojo_world::contracts::world::WorldContractReader;
Expand Down Expand Up @@ -109,12 +110,16 @@ struct Args {
explorer: bool,

/// Chunk size of the events page when indexing using events
#[arg(long, default_value = "1000")]
#[arg(long, default_value = "1024")]
events_chunk_size: u64,

/// Enable indexing pending blocks
#[arg(long)]
#[arg(long, action = ArgAction::Set, default_value_t = true)]
index_pending: bool,

/// Polling interval in ms
#[arg(long, default_value = "500")]
polling_interval: u64,
}

#[tokio::main]
Expand Down Expand Up @@ -188,7 +193,7 @@ async fn main() -> anyhow::Result<()> {
start_block: args.start_block,
events_chunk_size: args.events_chunk_size,
index_pending: args.index_pending,
..Default::default()
polling_interval: Duration::from_millis(args.polling_interval),
},
shutdown_tx.clone(),
Some(block_tx),
Expand Down
10 changes: 5 additions & 5 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) const LOG_TARGET: &str = "tori_core::engine";

#[derive(Debug)]
pub struct EngineConfig {
pub block_time: Duration,
pub polling_interval: Duration,
pub start_block: u64,
pub events_chunk_size: u64,
pub index_pending: bool,
Expand All @@ -45,10 +45,10 @@ pub struct EngineConfig {
impl Default for EngineConfig {
fn default() -> Self {
Self {
block_time: Duration::from_secs(1),
polling_interval: Duration::from_millis(500),
start_block: 0,
events_chunk_size: 1000,
index_pending: false,
events_chunk_size: 1024,
index_pending: true,
}
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<P: Provider + Sync> Engine<P> {
}
}
};
sleep(self.config.block_time).await;
sleep(self.config.polling_interval).await;
} => {}
}
}
Expand Down

0 comments on commit 4aa7454

Please sign in to comment.