Skip to content

Commit ca3d050

Browse files
authored
Call Fastly API sequentially (#15139)
1 parent 4d4322c commit ca3d050

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

ab-testing/deploy-lambda/src/lib/deploy.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,33 @@ export const fetchAndDeployArtifacts = async (deployments: ArtifactInfo[]) => {
1919
const CONFIG_PREFIX = `${STAGE}/config/ab-testing`;
2020

2121
try {
22-
await Promise.all(
22+
const artifacts = await Promise.all(
2323
deployments.map(async ({ artifact, dictionary }) => {
2424
console.log(
2525
`Fetching artifact /${ARTIFACT_BUCKET_NAME}${CONFIG_PREFIX}/${artifact} from S3 and deploying to Fastly dictionary ${dictionary.name}`,
2626
);
27-
const abTestGroups = await fetchDictionaryArtifact(
28-
ARTIFACT_BUCKET_NAME,
29-
`${CONFIG_PREFIX}/${artifact}`,
30-
);
31-
return await deployDictionary(dictionary, abTestGroups);
27+
return {
28+
dictionary,
29+
keyValues: await fetchDictionaryArtifact(
30+
ARTIFACT_BUCKET_NAME,
31+
`${CONFIG_PREFIX}/${artifact}`,
32+
),
33+
};
3234
}),
3335
);
36+
37+
for (const [i, { dictionary, keyValues }] of artifacts.entries()) {
38+
await deployDictionary(dictionary, keyValues);
39+
console.log(
40+
`Successfully deployed artifact to Fastly dictionary ${dictionary.name}`,
41+
);
42+
if (i !== artifacts.length - 1) {
43+
// Adding a small delay between calls to be sure the updates are not concurrent
44+
// See note in this section of the fastly docs
45+
// https://www.fastly.com/documentation/reference/api/#rate-limiting
46+
await new Promise((resolve) => setTimeout(resolve, 500));
47+
}
48+
}
3449
} catch (error) {
3550
console.error("Error in fetchAndDeployArtifacts:", error);
3651
throw error;

0 commit comments

Comments
 (0)