From 77190e46ac139620ae43655454f2a62ed1dd7b30 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Fri, 22 Nov 2024 11:39:02 -0500 Subject: [PATCH] Refresh perpetual markets cache markets are empty --- .../src/tasks/cache-orderbook-mid-prices.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/indexer/services/roundtable/src/tasks/cache-orderbook-mid-prices.ts b/indexer/services/roundtable/src/tasks/cache-orderbook-mid-prices.ts index c3ce43646b2..04abb05cee6 100644 --- a/indexer/services/roundtable/src/tasks/cache-orderbook-mid-prices.ts +++ b/indexer/services/roundtable/src/tasks/cache-orderbook-mid-prices.ts @@ -16,13 +16,22 @@ import { redisClient } from '../helpers/redis'; */ export default async function runTask(): Promise { try { - const perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap()); - const marketTickers = perpetualMarkets.map( + let perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap()); + let marketTickers = perpetualMarkets.map( (market: PerpetualMarketFromDatabase) => market.ticker, ); + // If no markets found, try updating the perpetual markets cache and fetch again if (marketTickers.length === 0) { - throw new Error('perpetualMarketRefresher is empty'); + await perpetualMarketRefresher.updatePerpetualMarkets(); + perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap()); + marketTickers = perpetualMarkets.map( + (market: PerpetualMarketFromDatabase) => market.ticker, + ); + + if (marketTickers.length === 0) { + throw new Error('perpetualMarketRefresher is empty'); + } } logger.info({