diff --git a/src/NotionExporter.ts b/src/NotionExporter.ts index bf2bff4..62df531 100644 --- a/src/NotionExporter.ts +++ b/src/NotionExporter.ts @@ -67,23 +67,21 @@ export class NotionExporter { return res.data.results.find((t: Task) => t.id === taskId) } - private pollTask = ( - taskId: string, - pollInterval: number = 50 - ): Promise => + private pollTask = (taskId: string): Promise => new Promise((resolve, reject) => { + const interval = this.config.pollInterval || defaultConfig.pollInterval const poll = async () => { const task = await this.getTask(taskId) if (task.state === "success" && task.status.exportURL) resolve(task.status.exportURL) else if (task.state === "in_progress" || task.state === "not_started") { - setTimeout(poll, pollInterval) + setTimeout(poll, interval) } else { console.error(taskId, task) reject(`Export task failed: ${taskId}.`) } } - setTimeout(poll, pollInterval) + setTimeout(poll, interval) }) /** diff --git a/src/config.ts b/src/config.ts index 2c36ae9..207f53d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,10 +10,13 @@ export interface Config { locale?: string /** Export all blocks of the DB/page or just the ones in the current view. Default: "all" */ collectionViewExportType?: "currentView" | "all" + /** Poll export task finished interval in ms */ + pollInterval?: number } export const defaultConfig: Config = { timeZone: "UTC", locale: "en", collectionViewExportType: "all", + pollInterval: 500, }