@@ -49,10 +49,24 @@ async function hydrateCacheForVaccine(
4949 approvalEnabled : boolean ,
5050 forceUpdate : boolean ,
5151) : Promise < HydrateCacheStatus > {
52+ log . info ( { context : { vaccineType } } , "Hydrating cache for given vaccine" ) ;
5253 const status : HydrateCacheStatus = { invalidatedCount : 0 , failureCount : 0 } ;
5354
55+ const rateLimitDelayMillis : number = 1000 / ( ( await config . CONTENT_API_RATE_LIMIT_PER_MINUTE ) / 60 ) ;
56+ const rateLimitDelayWithMargin : number = 2 * rateLimitDelayMillis ; // to keep ourselves well within the budget
57+
5458 try {
55- const content : string = await fetchContentForVaccine ( vaccineType ) ;
59+ const content : string = await retry ( ( ) => fetchContentForVaccine ( vaccineType ) , {
60+ retries : 2 ,
61+ delay : ( attempt : number ) => {
62+ const delayMillis = rateLimitDelayWithMargin * Math . pow ( 2 , attempt + 1 ) ;
63+ log . warn (
64+ { context : { vaccineType, attempt, delayMillis } } ,
65+ "Failed to fetch content for given vaccine, trying again" ,
66+ ) ;
67+ return delayMillis ;
68+ } ,
69+ } ) ;
5670 const filteredContent : VaccinePageContent = getFilteredContentForVaccine ( vaccineType , content ) ;
5771
5872 if ( ! approvalEnabled ) {
@@ -151,22 +165,18 @@ const runContentCacheHydrator = async (event: ContentCacheHydratorEvent) => {
151165 const rateLimitDelayMillis : number = 1000 / ( ( await config . CONTENT_API_RATE_LIMIT_PER_MINUTE ) / 60 ) ;
152166 const rateLimitDelayWithMargin : number = 2 * rateLimitDelayMillis ; // to keep ourselves well within the budget
153167 log . info ( `Delay used between calls to rate limit content API is ${ rateLimitDelayWithMargin } ms` ) ;
168+
154169 for ( const vaccine of vaccinesToRunOn ) {
155- const status = await retry (
156- async ( ) => hydrateCacheForVaccine ( vaccine , await config . CONTENT_CACHE_IS_CHANGE_APPROVAL_ENABLED , forceUpdate ) ,
157- {
158- retries : 3 ,
159- delay : ( attempt ) => {
160- const delayMillis = rateLimitDelayWithMargin * Math . pow ( 2 , attempt ) ;
161- log . warn ( { context : { vaccine, attempt, delayMillis } } , "Failed to hydrate cache, trying again" ) ;
162- return delayMillis ;
163- } ,
164- } ,
170+ const status = await hydrateCacheForVaccine (
171+ vaccine ,
172+ await config . CONTENT_CACHE_IS_CHANGE_APPROVAL_ENABLED ,
173+ forceUpdate ,
165174 ) ;
166175
167176 invalidatedCount += status . invalidatedCount ;
168177 failureCount += status . failureCount ;
169- await new Promise ( ( f ) => setTimeout ( f , rateLimitDelayWithMargin ) ) ; // sleep
178+
179+ await new Promise ( ( f ) => setTimeout ( f , rateLimitDelayWithMargin ) ) ; // sleep to rate limit
170180 }
171181
172182 log . info ( { context : { failureCount, invalidatedCount } } , "Finished hydrating content cache: report" ) ;
0 commit comments