From 9db4f12662d9de4f4162fffa0f7871383092f212 Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Mon, 9 Oct 2023 10:00:13 +0200 Subject: [PATCH] Sleep between notion cursors (#2008) --- connectors/src/connectors/notion/lib/notion_api.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/connectors/src/connectors/notion/lib/notion_api.ts b/connectors/src/connectors/notion/lib/notion_api.ts index 54d37720695d..50eb8332fafd 100644 --- a/connectors/src/connectors/notion/lib/notion_api.ts +++ b/connectors/src/connectors/notion/lib/notion_api.ts @@ -1268,7 +1268,8 @@ export async function* iteratePaginatedAPIWithRetries< retry: { retries: number; backoffFactor: number } = { retries: 5, backoffFactor: 2, - } + }, + sleepMs = 1000 ): AsyncIterableIterator { let nextCursor: string | null | undefined = firstPageArgs.start_cursor; let resultPageIdx = 0; @@ -1321,5 +1322,9 @@ export async function* iteratePaginatedAPIWithRetries< yield* response.results; nextCursor = response.next_cursor; resultPageIdx += 1; + + if (nextCursor && sleepMs) { + await new Promise((resolve) => setTimeout(resolve, sleepMs)); + } } while (nextCursor); }