@crawlee/basic 3.17.1-beta.59 → 3.17.1-beta.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -436,7 +436,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = BasicCrawlin
436
436
  userAgent?: string;
437
437
  };
438
438
  protected onSkippedRequest?: SkippedRequestCallback;
439
- private _closeEvents?;
439
+ private _ownsEventManager;
440
440
  private loggedPerRun;
441
441
  private experiments;
442
442
  private readonly robotsTxtFileCache;
@@ -336,11 +336,11 @@ class BasicCrawler {
336
336
  writable: true,
337
337
  value: void 0
338
338
  });
339
- Object.defineProperty(this, "_closeEvents", {
339
+ Object.defineProperty(this, "_ownsEventManager", {
340
340
  enumerable: true,
341
341
  configurable: true,
342
342
  writable: true,
343
- value: void 0
343
+ value: false
344
344
  });
345
345
  Object.defineProperty(this, "loggedPerRun", {
346
346
  enumerable: true,
@@ -655,8 +655,8 @@ class BasicCrawler {
655
655
  await this.autoscaledPool.run();
656
656
  }
657
657
  finally {
658
- await this.teardown();
659
658
  await this.stats.stopCapturing();
659
+ await this.teardown();
660
660
  process.off('SIGINT', sigintHandler);
661
661
  this.events.off("migrating" /* EventType.MIGRATING */, boundPauseOnMigration);
662
662
  this.events.off("aborting" /* EventType.ABORTING */, boundPauseOnMigration);
@@ -932,7 +932,7 @@ class BasicCrawler {
932
932
  async _init() {
933
933
  if (!this.events.isInitialized()) {
934
934
  await this.events.init();
935
- this._closeEvents = true;
935
+ this._ownsEventManager = true;
936
936
  }
937
937
  this.autoscaledPool = new core_1.AutoscaledPool(this.autoscaledPoolOptions, this.config);
938
938
  if (this.useSessionPool) {
@@ -1406,11 +1406,16 @@ class BasicCrawler {
1406
1406
  * To stop the crawler gracefully (waiting for all running requests to finish), use {@link BasicCrawler.stop|`crawler.stop()`} instead.
1407
1407
  */
1408
1408
  async teardown() {
1409
- this.events.emit("persistState" /* EventType.PERSIST_STATE */, { isMigrating: false });
1409
+ // When this crawler initialized the event manager, its close() call emits
1410
+ // the final persistence event after the crawler-specific state has been
1411
+ // saved. External event managers still need an explicit event here.
1412
+ if (!this._ownsEventManager) {
1413
+ this.events.emit("persistState" /* EventType.PERSIST_STATE */, { isMigrating: false });
1414
+ }
1410
1415
  if (this.useSessionPool) {
1411
- await this.sessionPool.teardown();
1416
+ await this.sessionPool.teardown({ persistState: this._ownsEventManager });
1412
1417
  }
1413
- if (this._closeEvents) {
1418
+ if (this._ownsEventManager) {
1414
1419
  await this.events.close();
1415
1420
  }
1416
1421
  await this.autoscaledPool?.abort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/basic",
3
- "version": "3.17.1-beta.59",
3
+ "version": "3.17.1-beta.60",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=16.0.0"
@@ -49,9 +49,9 @@
49
49
  "@apify/log": "^2.4.0",
50
50
  "@apify/timeout": "^0.4.0",
51
51
  "@apify/utilities": "^2.7.10",
52
- "@crawlee/core": "3.17.1-beta.59",
53
- "@crawlee/types": "3.17.1-beta.59",
54
- "@crawlee/utils": "3.17.1-beta.59",
52
+ "@crawlee/core": "3.17.1-beta.60",
53
+ "@crawlee/types": "3.17.1-beta.60",
54
+ "@crawlee/utils": "3.17.1-beta.60",
55
55
  "csv-stringify": "^6.2.0",
56
56
  "fs-extra": "^11.0.0",
57
57
  "got-scraping": "^4.2.1",
@@ -67,5 +67,5 @@
67
67
  }
68
68
  }
69
69
  },
70
- "gitHead": "8980103b700213806843d4fe1355b75519474ea4"
70
+ "gitHead": "5ba2517b5f3bc6ef868b860c6c783a3e7e7d4a93"
71
71
  }