[mining] fix pools updater only running at start
This commit is contained in:
parent
db10ab9aae
commit
ae2ed8fdae
@ -32,6 +32,7 @@ interface IConfig {
|
|||||||
AUTOMATIC_POOLS_UPDATE: boolean;
|
AUTOMATIC_POOLS_UPDATE: boolean;
|
||||||
POOLS_JSON_URL: string,
|
POOLS_JSON_URL: string,
|
||||||
POOLS_JSON_TREE_URL: string,
|
POOLS_JSON_TREE_URL: string,
|
||||||
|
POOLS_UPDATE_DELAY: number,
|
||||||
AUDIT: boolean;
|
AUDIT: boolean;
|
||||||
RUST_GBT: boolean;
|
RUST_GBT: boolean;
|
||||||
LIMIT_GBT: boolean;
|
LIMIT_GBT: boolean;
|
||||||
@ -192,6 +193,7 @@ const defaults: IConfig = {
|
|||||||
'AUTOMATIC_POOLS_UPDATE': false,
|
'AUTOMATIC_POOLS_UPDATE': false,
|
||||||
'POOLS_JSON_URL': 'https://raw.githubusercontent.com/mempool/mining-pools/master/pools-v2.json',
|
'POOLS_JSON_URL': 'https://raw.githubusercontent.com/mempool/mining-pools/master/pools-v2.json',
|
||||||
'POOLS_JSON_TREE_URL': 'https://api.github.com/repos/mempool/mining-pools/git/trees/master',
|
'POOLS_JSON_TREE_URL': 'https://api.github.com/repos/mempool/mining-pools/git/trees/master',
|
||||||
|
'POOLS_UPDATE_DELAY': 604800, // in seconds, default is one week
|
||||||
'AUDIT': false,
|
'AUDIT': false,
|
||||||
'RUST_GBT': false,
|
'RUST_GBT': false,
|
||||||
'LIMIT_GBT': false,
|
'LIMIT_GBT': false,
|
||||||
|
@ -239,6 +239,7 @@ class Server {
|
|||||||
if (config.FIAT_PRICE.ENABLED) {
|
if (config.FIAT_PRICE.ENABLED) {
|
||||||
priceUpdater.$run();
|
priceUpdater.$run();
|
||||||
}
|
}
|
||||||
|
await poolsUpdater.updatePoolsJson();
|
||||||
|
|
||||||
// rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS
|
// rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS
|
||||||
const elapsed = Date.now() - start;
|
const elapsed = Date.now() - start;
|
||||||
|
@ -23,11 +23,8 @@ class PoolsUpdater {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oneWeek = 604800;
|
|
||||||
const oneDay = 86400;
|
|
||||||
|
|
||||||
const now = new Date().getTime() / 1000;
|
const now = new Date().getTime() / 1000;
|
||||||
if (now - this.lastRun < oneWeek) { // Execute the PoolsUpdate only once a week, or upon restart
|
if (now - this.lastRun < config.MEMPOOL.POOLS_UPDATE_DELAY) { // Execute the PoolsUpdate only once a week, or upon restart
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +84,8 @@ class PoolsUpdater {
|
|||||||
logger.info(`Mining pools-v2.json (${githubSha}) import completed`);
|
logger.info(`Mining pools-v2.json (${githubSha}) import completed`);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.lastRun = now - (oneWeek - oneDay); // Try again in 24h instead of waiting next week
|
this.lastRun = now - 600; // Try again in 10 minutes
|
||||||
logger.err(`PoolsUpdater failed. Will try again in 24h. Exception: ${JSON.stringify(e)}`, logger.tags.mining);
|
logger.err(`PoolsUpdater failed. Will try again in 10 minutes. Exception: ${JSON.stringify(e)}`, logger.tags.mining);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user