Skip to content

Commit

Permalink
Merge pull request #787 from near/phuong/fix/bump-indexer-running
Browse files Browse the repository at this point in the history
fix: bump indexer to 5mins instead of 60s
  • Loading branch information
ppca authored Jul 31, 2024
2 parents 862de64 + f9622ef commit 28646e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions chain-signatures/node/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct Indexer {

impl Indexer {
const BEHIND_THRESHOLD: Duration = Duration::from_secs(60);
const RUNNING_THRESHOLD: Duration = Duration::from_secs(5 * 60);

fn new(latest_block_height: LatestBlockHeight) -> Self {
Self {
Expand All @@ -113,6 +114,11 @@ impl Indexer {
self.last_updated_timestamp.read().await.elapsed() <= Self::BEHIND_THRESHOLD
}

/// Check whether the indexer is on track with the latest block height from the chain.
pub async fn is_running(&self) -> bool {
self.last_updated_timestamp.read().await.elapsed() <= Self::RUNNING_THRESHOLD
}

/// Check whether the indexer is behind with the latest block height from the chain.
pub async fn is_behind(&self) -> bool {
self.last_updated_timestamp.read().await.elapsed() > Self::BEHIND_THRESHOLD
Expand Down Expand Up @@ -330,10 +336,10 @@ pub fn run(
rt.spawn(async move { lake.run_with_context_async(handle_block, &context).await })
};
let outcome = rt.block_on(async {
// while on track, we will keep the task spinning, and check every so often if
// while running, we will keep the task spinning, and check every so often if
// the indexer has errored out.
while context.indexer.is_on_track().await {
tokio::time::sleep(Duration::from_secs(5)).await;
while context.indexer.is_running().await {
tokio::time::sleep(Duration::from_secs(60)).await;
if join_handle.is_finished() {
break;
}
Expand Down

0 comments on commit 28646e9

Please sign in to comment.