Skip to content

Commit 9d62d56

Browse files
committed
fix: wait for storage to finish before resolving crawler.run()
1 parent 2beec9c commit 9d62d56

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/basic-crawler/src/internals/basic-crawler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,19 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
579579
};
580580
this.log.info('Crawl finished. Final request statistics:', stats);
581581

582+
const client = this.config.getStorageClient();
583+
584+
if (client.teardown) {
585+
let finished = false;
586+
setTimeout(() => {
587+
if (!finished) {
588+
this.log.info('Waiting for the storage to write its state to file system.');
589+
}
590+
}, 1000);
591+
await client.teardown();
592+
finished = true;
593+
}
594+
582595
return stats;
583596
}
584597

0 commit comments

Comments
 (0)