Skip to content

Commit

Permalink
Update cron-cache-gas-costs.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Jan 14, 2025
1 parent f8a31d9 commit 7a5ec18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/cron-cache-gas-costs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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",
Expand Down

0 comments on commit 7a5ec18

Please sign in to comment.