Merge pull request #1930 from mempool/nymkappa/bugfix/retry-indexing-upon-error
If indexing fails try again in 10 seconds
This commit is contained in:
		
						commit
						b965041369
					
				@ -295,7 +295,8 @@ class Blocks {
 | 
			
		||||
      }
 | 
			
		||||
      logger.notice(`Blocks summaries indexing completed: indexed ${newlyIndexed} blocks`);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.err(`Blocks summaries indexing failed. Reason: ${(e instanceof Error ? e.message : e)}`);
 | 
			
		||||
      logger.err(`Blocks summaries indexing failed. Trying again in 10 seconds. Reason: ${(e instanceof Error ? e.message : e)}`);
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -367,18 +368,12 @@ class Blocks {
 | 
			
		||||
      logger.notice(`Block indexing completed: indexed ${newlyIndexed} blocks`);
 | 
			
		||||
      loadingIndicators.setProgress('block-indexing', 100);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.err('Block indexing failed. Trying again later. Reason: ' + (e instanceof Error ? e.message : e));
 | 
			
		||||
      logger.err('Block indexing failed. Trying again in 10 seconds. Reason: ' + (e instanceof Error ? e.message : e));
 | 
			
		||||
      loadingIndicators.setProgress('block-indexing', 100);
 | 
			
		||||
      return false;
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const chainValid = await BlocksRepository.$validateChain();
 | 
			
		||||
    if (!chainValid) {
 | 
			
		||||
      indexer.reindex();
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
    return await BlocksRepository.$validateChain();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $updateBlocks() {
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ import logger from '../logger';
 | 
			
		||||
import { Common } from './common';
 | 
			
		||||
import loadingIndicators from './loading-indicators';
 | 
			
		||||
import { escape } from 'mysql2';
 | 
			
		||||
import indexer from '../indexer';
 | 
			
		||||
import DifficultyAdjustmentsRepository from '../repositories/DifficultyAdjustmentsRepository';
 | 
			
		||||
 | 
			
		||||
class Mining {
 | 
			
		||||
@ -263,6 +264,7 @@ class Mining {
 | 
			
		||||
      loadingIndicators.setProgress('weekly-hashrate-indexing', 100);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      loadingIndicators.setProgress('weekly-hashrate-indexing', 100);
 | 
			
		||||
      logger.err(`Weekly mining pools hashrates indexing failed. Trying again in 10 seconds. Reason: ${(e instanceof Error ? e.message : e)}`);
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@ -374,6 +376,7 @@ class Mining {
 | 
			
		||||
      loadingIndicators.setProgress('daily-hashrate-indexing', 100);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      loadingIndicators.setProgress('daily-hashrate-indexing', 100);
 | 
			
		||||
      logger.err(`Daily network hashrate indexing failed. Trying again in 10 seconds. Reason: ${(e instanceof Error ? e.message : e)}`);
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -39,6 +39,8 @@ class Indexer {
 | 
			
		||||
      const chainValid = await blocks.$generateBlockDatabase();
 | 
			
		||||
      if (chainValid === false) {
 | 
			
		||||
        // Chain of block hash was invalid, so we need to reindex. Stop here and continue at the next iteration
 | 
			
		||||
        logger.warn(`The chain of block hash is invalid, re-indexing invalid data in 10 seconds.`);
 | 
			
		||||
        setTimeout(() => this.reindex(), 10000);
 | 
			
		||||
        this.indexerRunning = false;
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
@ -49,8 +51,9 @@ class Indexer {
 | 
			
		||||
      await mining.$generatePoolHashrateHistory();
 | 
			
		||||
      await blocks.$generateBlocksSummariesDatabase();
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      this.reindex();
 | 
			
		||||
      logger.err(`Indexer failed, trying again later. Reason: ` + (e instanceof Error ? e.message : e));
 | 
			
		||||
      this.indexerRunning = false;
 | 
			
		||||
      logger.err(`Indexer failed, trying again in 10 seconds. Reason: ` + (e instanceof Error ? e.message : e));
 | 
			
		||||
      setTimeout(() => this.reindex(), 10000);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.indexerRunning = false;
 | 
			
		||||
@ -62,6 +65,7 @@ class Indexer {
 | 
			
		||||
      await HashratesRepository.$setLatestRun('last_weekly_hashrates_indexing', 0);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.err(`Cannot reset hashrate indexing timestamps. Reason: ` + (e instanceof Error ? e.message : e));
 | 
			
		||||
      throw e;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user