Skip to content

Commit 8350113

Browse files
authored
Merge pull request #81 from sillsdev/moreTimeoutResilience
fix: Increase timeout resilience (#81)
2 parents f077368 + c7a6d93 commit 8350113

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"// typescript check": "",
1212
"tsc": "tsc",
1313
"// test out with a private sample notion db": "",
14-
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr",
14+
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr --log-level debug",
1515
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
1616
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
1717
"// test with a semi-stable/public site:": "",

src/pull.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,12 @@ export async function executeWithRateLimitAndRetries<T>(
284284
e.message.includes("timeout") ||
285285
e.message.includes("Timeout") ||
286286
e.message.includes("limit") ||
287-
e.message.includes("Limit")
287+
e.message.includes("Limit") ||
288+
e?.code === "notionhq_client_response_error" ||
289+
e?.code === "service_unavailable"
288290
) {
289291
const secondsToWait = i + 1;
290-
info(
292+
warning(
291293
`While doing "${label}", got error "${
292294
e.message as string
293295
}". Will retry after ${secondsToWait}s...`

src/transform.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { error, info, logDebug, logDebugFn, verbose, warning } from "./log";
77
import { NotionPage } from "./NotionPage";
88
import { IDocuNotionConfig } from "./config/configuration";
99
import { NotionBlock } from "./types";
10+
import { executeWithRateLimitAndRetries } from "./pull";
1011

1112
export async function getMarkdownForPage(
1213
config: IDocuNotionConfig,
@@ -157,8 +158,14 @@ async function doNotionToMarkdown(
157158
docunotionContext: IDocuNotionContext,
158159
blocks: Array<NotionBlock>
159160
) {
160-
const mdBlocks = await docunotionContext.notionToMarkdown.blocksToMarkdown(
161-
blocks
161+
let mdBlocks: any;
162+
await executeWithRateLimitAndRetries(
163+
"notionToMarkdown.blocksToMarkdown",
164+
async () => {
165+
mdBlocks = await docunotionContext.notionToMarkdown.blocksToMarkdown(
166+
blocks
167+
);
168+
}
162169
);
163170

164171
const markdown =

0 commit comments

Comments
 (0)