Merge pull request #1298 from nymkappa/feature/fix-hashrate-indexing-try-catch

Make sure to reset hashrates indexing flags upon error
This commit is contained in:
softsimon 2022-03-05 16:30:12 +01:00 committed by GitHub
commit e131ec883b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 89 deletions

View File

@ -108,6 +108,8 @@ class Mining {
if (!blocks.blockIndexingCompleted || this.hashrateIndexingStarted) {
return;
}
try {
this.hashrateIndexingStarted = true;
logger.info(`Indexing hashrates`);
@ -143,7 +145,7 @@ class Mining {
blockStats.lastBlockHeight);
if (totalIndexed > 7 && totalIndexed % 7 === 0 && !indexedTimestamp.includes(fromTimestamp + 1)) { // Save weekly pools hashrate
logger.debug(`Indexing weekly hashrates for mining pools (timestamp: ${fromTimestamp})`);
logger.debug("Indexing weekly hashrates for mining pools");
let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp - 604800, fromTimestamp);
const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0);
pools = pools.map((pool: any) => {
@ -208,6 +210,10 @@ class Mining {
this.hashrateIndexingStarted = false;
logger.info(`Hashrates indexing completed`);
} catch (e) {
this.hashrateIndexingStarted = false;
throw e;
}
}
}

View File

@ -22,6 +22,7 @@ class HashratesRepository {
await connection.query(query);
} catch (e: any) {
logger.err('$saveHashrateInDatabase() error' + (e instanceof Error ? e.message : e));
throw e;
}
connection.release();