Skip to content

Commit

Permalink
feat: info log if no new blocks are published in the last 20 seconds …
Browse files Browse the repository at this point in the history
…to avoid people thinking rindexer is stuck
  • Loading branch information
joshstevens19 committed Sep 17, 2024
1 parent 857f63a commit aeec1f1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/database/postgres/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn setup_postgres(
let client = PostgresClient::new().await?;

let disable_event_tables = manifest.storage.postgres_disable_create_tables();

if manifest.storage.postgres_drop_each_run() {
info!(
"`drop_each_run` enabled so dropping all data for {} before starting",
Expand Down
21 changes: 19 additions & 2 deletions core/src/indexer/fetch_logs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::{error::Error, str::FromStr, sync::Arc};
use std::{error::Error, str::FromStr, sync::Arc, time::Duration};

use ethers::{
addressbook::Address,
middleware::MiddlewareError,
prelude::{BlockNumber, JsonRpcError, Log, ValueOrArray, H256, U64},
};
use regex::Regex;
use tokio::sync::{mpsc, Semaphore};
use tokio::{
sync::{mpsc, Semaphore},
time::Instant,
};
use tokio_stream::wrappers::UnboundedReceiverStream;
use tracing::{debug, error, info, warn};

Expand Down Expand Up @@ -325,6 +328,11 @@ async fn live_indexing_stream(
disable_logs_bloom_checks: bool,
) {
let mut last_seen_block_number = U64::from(0);

// this is used for less busy chains to make sure they know rindexer is still alive
let mut last_no_new_block_log_time = Instant::now();
let log_no_new_block_interval = Duration::from_secs(20);

loop {
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;

Expand All @@ -339,6 +347,15 @@ async fn live_indexing_stream(
info_log_name,
IndexingEventProgressStatus::Live.log()
);
if last_no_new_block_log_time.elapsed() >= log_no_new_block_interval {
info!(
"{} - {} - No new blocks published in the last 20 seconds - latest block number {}",
info_log_name,
IndexingEventProgressStatus::Live.log(),
last_seen_block_number,
);
last_no_new_block_log_time = Instant::now();
}
continue;
}
info!(
Expand Down
19 changes: 17 additions & 2 deletions core/src/indexer/process.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Arc};
use std::{collections::HashMap, sync::Arc, time::Duration};

use async_std::prelude::StreamExt;
use ethers::{
Expand All @@ -9,6 +9,7 @@ use futures::future::join_all;
use tokio::{
sync::{Mutex, MutexGuard},
task::{JoinError, JoinHandle},
time::Instant,
};
use tracing::{debug, error, info};

Expand Down Expand Up @@ -213,8 +214,12 @@ async fn live_indexing_for_contract_event_dependencies<'a>(
);
}

// this is used for less busy chains to make sure they know rindexer is still alive
let mut last_no_new_block_log_time = Instant::now();
let log_no_new_block_interval = Duration::from_secs(20);

loop {
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;

for (config, _) in live_indexing_events.iter() {
let mut ordering_live_indexing_details = ordering_live_indexing_details_map
Expand All @@ -238,6 +243,16 @@ async fn live_indexing_for_contract_event_dependencies<'a>(
&config.info_log_name,
IndexingEventProgressStatus::Live.log()
);
if last_no_new_block_log_time.elapsed() >= log_no_new_block_interval
{
info!(
"{} - {} - No new blocks published in the last 20 seconds - latest block number {}",
&config.info_log_name,
IndexingEventProgressStatus::Live.log(),
latest_block_number
);
last_no_new_block_log_time = Instant::now();
}
continue;
}
info!(
Expand Down
1 change: 1 addition & 0 deletions documentation/docs/pages/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Features
-------------------------------------------------
- feat: info log if no new blocks are published in the last 20 seconds to avoid people thinking rindexer is stuck

### Bug fixes
-------------------------------------------------
Expand Down

0 comments on commit aeec1f1

Please sign in to comment.