Skip to content

Commit a259560

Browse files
authored
No Exit Run Loop (#189)
1 parent e70ca00 commit a259560

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

event-handler/src/cli.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct Args {
3030
pub chain_source: ChainDataSource,
3131

3232
/// BlockRange width for run-loop processing.
33-
#[clap(long, env, default_value = "1000")]
33+
#[clap(long, env, default_value = "25")]
3434
pub page_size: i64,
3535

3636
/// TokenUri retry blocks
@@ -48,4 +48,8 @@ pub struct Args {
4848
/// List of Token Contract addresses to avoid making tokenUri requests for.
4949
#[clap(long, env, use_value_delimiter = true)]
5050
pub token_avoid_list: Vec<Address>,
51+
52+
/// Wait time for new finalized blocks
53+
#[clap(long, env, default_value = "180")]
54+
pub arak_poll_frequency: u64,
5155
}

event-handler/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ async fn main() -> Result<()> {
3636

3737
let start_from = handler.store.get_processed_block() + 1;
3838
tracing::info!("beginning event processor from {start_from}");
39-
handler.run(start_from).await
39+
handler.run(start_from, args.arak_poll_frequency).await
4040
}

event-handler/src/processor.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use event_retriever::db_reader::{
1414
diesel::{BlockRange, EventSource},
1515
models::*,
1616
};
17+
use std::time::Duration;
1718
use std::{collections::HashMap, sync::Arc};
1819

1920
pub struct EventProcessor {
@@ -52,15 +53,27 @@ impl EventProcessor {
5253
metadata_client,
5354
})
5455
}
56+
pub async fn run(&mut self, start_from: i64, wait_secs: u64) -> Result<()> {
57+
let mut current_block = start_from;
58+
loop {
59+
current_block = self.run_inner(current_block).await?;
60+
// Sleep for a bit and reenter the loop.
61+
tracing::info!(
62+
"Reached the last finalized block. Waiting for {} for more...",
63+
wait_secs
64+
);
65+
tokio::time::sleep(Duration::from_secs(wait_secs)).await;
66+
}
67+
}
5568

56-
pub async fn run(&mut self, start_from: i64) -> Result<()> {
69+
pub async fn run_inner(&mut self, start_from: i64) -> Result<i64> {
5770
let mut current_block = start_from;
5871
loop {
5972
// TODO - (after reorg handling) Replace with get_indexed_block (finalized is safe)
6073
// https://github.com/Mintbase/evm-indexer/issues/104
6174
let max_block = self.source.get_finalized_block();
6275

63-
if current_block > max_block {
76+
if current_block >= max_block {
6477
// Exit when reached or exceeded the max_block
6578
break;
6679
}
@@ -76,8 +89,7 @@ impl EventProcessor {
7689
// Update current_block for the next iteration
7790
current_block = block_range.end;
7891
}
79-
80-
Ok(())
92+
Ok(current_block)
8193
}
8294

8395
fn check_for_contract(&mut self, event: &EventBase) {
@@ -293,7 +305,7 @@ mod tests {
293305
async fn test_run() {
294306
let mut handler = test_processor().await;
295307
let start_from = std::cmp::max(handler.store.get_processed_block() + 1, 15_000_000);
296-
let result = handler.run(start_from).await;
308+
let result = handler.run(start_from, 5).await;
297309
assert!(result.is_ok());
298310
}
299311
}

metadata-retriever/src/routes/token/metadata/homebrew.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ mod tests {
136136
}
137137

138138
#[tokio::test]
139+
#[ignore = "unreliable responses - for local testing only"]
139140
async fn url_request_certificate_errors() {
140141
// Untrusted Certificate
141142
let urls = [
@@ -166,7 +167,7 @@ mod tests {
166167
// assert_eq!(error_set.len(), 1);
167168
}
168169
#[tokio::test]
169-
#[ignore = "unreliable responses"]
170+
#[ignore = "unreliable responses - for local testing only"]
170171
async fn url_request_error_trying_to_connect() {
171172
// DNS Error
172173
// There are several variants of DNS error:
@@ -296,7 +297,7 @@ mod tests {
296297
}
297298

298299
#[tokio::test]
299-
#[ignore = "unreliable responses"]
300+
#[ignore = "unreliable responses - for local testing only"]
300301
async fn url_request_500_status_errors() {
301302
// 500 Internal Server Error
302303
assert!(
@@ -382,6 +383,7 @@ mod tests {
382383
}
383384

384385
#[tokio::test]
386+
#[ignore = "ENS metadata domain is down: https://metadata.ens.domains"]
385387
async fn ens_override() {
386388
let token_id =
387389
"31913142322058250240866303485500832898255309823098443696464130050119537886147";

0 commit comments

Comments
 (0)