Skip to content

Commit 47e9ca8

Browse files
VIA-615 AJ Increase delay factor to further rate limit
1 parent e9b0c91 commit 47e9ca8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/_lambda/content-cache-hydrator/handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { logger } from "@src/utils/logger";
1212
import { getVaccineTypeFromLowercaseString } from "@src/utils/path";
1313
import { RequestContext, asyncLocalStorage } from "@src/utils/requestContext";
1414
import { Context } from "aws-lambda";
15-
import { retry } from "es-toolkit";
15+
import { delay, retry } from "es-toolkit";
1616

1717
const 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

Comments
 (0)