From 7a5ec184ada5a96b7bebefd7bfd1defbdfe6167e Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Mon, 13 Jan 2025 19:46:11 -0700 Subject: [PATCH] Update cron-cache-gas-costs.ts --- api/cron-cache-gas-costs.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/cron-cache-gas-costs.ts b/api/cron-cache-gas-costs.ts index 624b526c4..c9dd4b9af 100644 --- a/api/cron-cache-gas-costs.ts +++ b/api/cron-cache-gas-costs.ts @@ -34,7 +34,7 @@ const updateL1DataFeeIntervalsSecPerChain = { // Set lower than TTL in getCachedNativeGasCost. This should rarely change so we should just make sure // we keep this cache warm. const updateNativeGasCostIntervalsSecPerChain = { - default: 30, + default: 20, }; const maxDurationSec = 60; @@ -163,7 +163,7 @@ const handler = async ( // But we want to update gas data more frequently than that. // To circumvent this, we run the function in a loop and update gas prices every // `secondsPerUpdateForChain` seconds and stop after `maxDurationSec` seconds (1 minute). - await Promise.all([ + const cacheUpdatePromises = Promise.all([ Promise.all( mainnetChains.map(async (chain) => { const routesToChain = availableRoutes.filter( @@ -188,6 +188,11 @@ const handler = async ( ), ]); + // The above promises are supposed to complete after maxDurationSec seconds, but there are so many of them + // (one per route) that they last one can run quite a bit longer, so force the function to stop after maxDurationSec + // so that the serverless function can exit successfully. + await Promise.race([cacheUpdatePromises, utils.delay(maxDurationSec)]); + logger.debug({ at: "CronCacheGasPrices", message: "Finished",