@@ -12,7 +12,7 @@ import { logger } from "@src/utils/logger";
1212import { getVaccineTypeFromLowercaseString } from "@src/utils/path" ;
1313import { RequestContext , asyncLocalStorage } from "@src/utils/requestContext" ;
1414import { Context } from "aws-lambda" ;
15- import { retry } from "es-toolkit" ;
15+ import { delay , retry } from "es-toolkit" ;
1616
1717const log = logger . child ( { module : "content-cache-hydrator" } ) ;
1818
@@ -56,7 +56,7 @@ async function hydrateCacheForVaccine(
5656 const rateLimitDelayWithMargin : number = 2 * rateLimitDelayMillis ; // to keep ourselves well within the budget
5757
5858 try {
59- const content : string = await retry ( ( ) => fetchContentForVaccine ( vaccineType ) , {
59+ const content : string = await retry ( async ( ) => fetchContentForVaccine ( vaccineType ) , {
6060 retries : 2 ,
6161 delay : ( attempt : number ) => {
6262 const delayMillis = rateLimitDelayWithMargin * Math . pow ( 2 , attempt + 1 ) ;
@@ -163,7 +163,7 @@ const runContentCacheHydrator = async (event: ContentCacheHydratorEvent) => {
163163 let invalidatedCount : number = 0 ;
164164
165165 const rateLimitDelayMillis : number = 1000 / ( ( await config . CONTENT_API_RATE_LIMIT_PER_MINUTE ) / 60 ) ;
166- const rateLimitDelayWithMargin : number = 2 * rateLimitDelayMillis ; // to keep ourselves well within the budget
166+ const rateLimitDelayWithMargin : number = 2.5 * rateLimitDelayMillis ; // to keep ourselves well within the budget
167167 log . info ( `Delay used between calls to rate limit content API is ${ rateLimitDelayWithMargin } ms` ) ;
168168
169169 for ( const vaccine of vaccinesToRunOn ) {
@@ -176,7 +176,7 @@ const runContentCacheHydrator = async (event: ContentCacheHydratorEvent) => {
176176 invalidatedCount += status . invalidatedCount ;
177177 failureCount += status . failureCount ;
178178
179- await new Promise ( ( f ) => setTimeout ( f , rateLimitDelayWithMargin ) ) ; // sleep to rate limit
179+ await delay ( rateLimitDelayWithMargin ) ; // sleep to rate limit
180180 }
181181
182182 log . info ( { context : { failureCount, invalidatedCount } } , "Finished hydrating content cache: report" ) ;
0 commit comments