Allow priceUpdater to run without storing to database
This commit is contained in:
		
							parent
							
								
									8331535562
								
							
						
					
					
						commit
						4ffc3d0ce5
					
				@ -194,6 +194,7 @@ class Server {
 | 
			
		||||
        await memPool.$updateMempool(newMempool, pollRate);
 | 
			
		||||
      }
 | 
			
		||||
      indexer.$run();
 | 
			
		||||
      priceUpdater.$run();
 | 
			
		||||
 | 
			
		||||
      // rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS
 | 
			
		||||
      const elapsed = Date.now() - start;
 | 
			
		||||
 | 
			
		||||
@ -106,7 +106,7 @@ class Indexer {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      await priceUpdater.$run();
 | 
			
		||||
      await priceUpdater.$run(true);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.err(`Running priceUpdater failed. Reason: ` + (e instanceof Error ? e.message : e));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -72,7 +72,7 @@ class PriceUpdater {
 | 
			
		||||
    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') {
 | 
			
		||||
      // Coins have no value on testnet/signet, so we want to always show 0
 | 
			
		||||
      return;
 | 
			
		||||
@ -89,7 +89,7 @@ class PriceUpdater {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      await this.$updatePrice();
 | 
			
		||||
      await this.$updatePrice(storeInDb);
 | 
			
		||||
      if (this.historyInserted === false && config.DATABASE.ENABLED === true) {
 | 
			
		||||
        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
 | 
			
		||||
   */
 | 
			
		||||
  private async $updatePrice(): Promise<void> {
 | 
			
		||||
  private async $updatePrice(storeInDb: boolean): Promise<void> {
 | 
			
		||||
    if (this.lastRun === 0 && config.DATABASE.ENABLED === true) {
 | 
			
		||||
      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
 | 
			
		||||
      try {
 | 
			
		||||
        const p = 60 * 60 * 1000; // milliseconds in an hour
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user