Allow priceUpdater to run without storing to database
This commit is contained in:
parent
83a487ecae
commit
af4d0b4d3f
@ -194,6 +194,7 @@ class Server {
|
|||||||
await memPool.$updateMempool(newMempool, pollRate);
|
await memPool.$updateMempool(newMempool, pollRate);
|
||||||
}
|
}
|
||||||
indexer.$run();
|
indexer.$run();
|
||||||
|
priceUpdater.$run();
|
||||||
|
|
||||||
// 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;
|
||||||
|
@ -106,7 +106,7 @@ class Indexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await priceUpdater.$run();
|
await priceUpdater.$run(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.err(`Running priceUpdater failed. Reason: ` + (e instanceof Error ? e.message : e));
|
logger.err(`Running priceUpdater failed. Reason: ` + (e instanceof Error ? e.message : e));
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class PriceUpdater {
|
|||||||
this.latestPrices = await PricesRepository.$getLatestConversionRates();
|
this.latestPrices = await PricesRepository.$getLatestConversionRates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async $run(): Promise<void> {
|
public async $run(storeInDb: boolean = false): Promise<void> {
|
||||||
if (config.MEMPOOL.NETWORK === 'signet' || config.MEMPOOL.NETWORK === 'testnet') {
|
if (config.MEMPOOL.NETWORK === 'signet' || config.MEMPOOL.NETWORK === 'testnet') {
|
||||||
// Coins have no value on testnet/signet, so we want to always show 0
|
// Coins have no value on testnet/signet, so we want to always show 0
|
||||||
return;
|
return;
|
||||||
@ -89,7 +89,7 @@ class PriceUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.$updatePrice();
|
await this.$updatePrice(storeInDb);
|
||||||
if (this.historyInserted === false && config.DATABASE.ENABLED === true) {
|
if (this.historyInserted === false && config.DATABASE.ENABLED === true) {
|
||||||
await this.$insertHistoricalPrices();
|
await this.$insertHistoricalPrices();
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class PriceUpdater {
|
|||||||
/**
|
/**
|
||||||
* Fetch last BTC price from exchanges, average them, and save it in the database once every hour
|
* Fetch last BTC price from exchanges, average them, and save it in the database once every hour
|
||||||
*/
|
*/
|
||||||
private async $updatePrice(): Promise<void> {
|
private async $updatePrice(storeInDb: boolean): Promise<void> {
|
||||||
if (this.lastRun === 0 && config.DATABASE.ENABLED === true) {
|
if (this.lastRun === 0 && config.DATABASE.ENABLED === true) {
|
||||||
this.lastRun = await PricesRepository.$getLatestPriceTime();
|
this.lastRun = await PricesRepository.$getLatestPriceTime();
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ class PriceUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.DATABASE.ENABLED === true) {
|
if (config.DATABASE.ENABLED === true && storeInDb) {
|
||||||
// Save everything in db
|
// Save everything in db
|
||||||
try {
|
try {
|
||||||
const p = 60 * 60 * 1000; // milliseconds in an hour
|
const p = 60 * 60 * 1000; // milliseconds in an hour
|
||||||
|
Loading…
x
Reference in New Issue
Block a user