Add retries when getting page from GitBook (#7611)

GitBook API occasionally throws a 500 when trying to get a page. This makes our whole sync Lambda fail.

This commit adds a retry step, that will wait a second and retry the GitBook API, with retries capped to three, so the Lambda is a little more resilient to random 500s from GitBook API.
This commit is contained in:
Shrikant Sharat Kandula 2021-09-20 12:34:04 +05:30 committed by GitHub
parent 4288b44f2c
commit fae8de553d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,6 +56,17 @@ function getPage(pageId) {
});
}
async function getPageRetry(pageId, retries) {
while (retries-- > 0) {
try {
return await getPage(pageId);
} catch (error) {
continue;
}
}
throw new Error("Tried getting page " + retries + " times, but failed.");
}
const pages = [];
@ -100,7 +111,7 @@ exports.handler = async (event, context, callback) => {
pages.push(masterPage);
let promises = pages.map(page => page.uid).map(getPage);
let promises = pages.map(page => page.uid).map(pageId => getPageRetry(pageId, 3));
Promise.all(promises).then(updatedPages => {