apify 4.0.0-beta.106 → 4.0.0-beta.107

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.
package/dist/actor.d.ts CHANGED
@@ -323,6 +323,11 @@ export interface MetamorphOptions {
323
323
  customAfterSleepMillis?: number;
324
324
  }
325
325
  export interface RebootOptions {
326
+ /**
327
+ * Amount of time, in seconds, to wait for the `persistState` and `migrating` event handlers before rebooting.
328
+ * @default 30
329
+ */
330
+ timeoutSecs?: number;
326
331
  /** @internal */
327
332
  customAfterSleepMillis?: number;
328
333
  }
package/dist/actor.js CHANGED
@@ -9,6 +9,7 @@ import { ACTOR_ENV_VARS, ACTOR_EVENT_NAMES, APIFY_ENV_VARS, INTEGER_ENV_VARS, ME
9
9
  import { decryptInputSecrets } from '@apify/input_secrets';
10
10
  import log from '@apify/log';
11
11
  import { addTimeoutToPromise } from '@apify/timeout';
12
+ import { timeoutPromise } from '@apify/utilities';
12
13
  import { parseArgument } from '@apify/validations';
13
14
  import { ApifyFileSystemStorageBackend } from './apify_file_system_storage_backend.js';
14
15
  import { ApifyStorageBackend } from './apify_storage_backend.js';
@@ -687,23 +688,36 @@ export class Actor {
687
688
  return;
688
689
  }
689
690
  this.#isRebooting = true;
691
+ const { timeoutSecs = 30, customAfterSleepMillis = this.configuration.metamorphAfterSleepMillis } = options;
692
+ const callListeners = (event, data) => serviceLocator
693
+ .getEventManager()
694
+ .listeners(event)
695
+ .map(async (listener) => {
696
+ try {
697
+ await listener(data);
698
+ }
699
+ catch (err) {
700
+ log.exception(err, 'A pre-reboot event listener failed');
701
+ }
702
+ });
690
703
  // Waiting for all the listeners to finish, as `.reboot()` kills the container.
691
- await Promise.all([
704
+ // Not using `addTimeoutToPromise`, its timeout would also cancel the enclosing one (e.g. a request handler).
705
+ await timeoutPromise(Promise.all([
692
706
  // `persistState` for individual RequestLists, RequestQueue... instances to be persisted
693
- ...serviceLocator
694
- .getEventManager()
695
- .listeners(EventType.PERSIST_STATE)
696
- .map(async (x) => x({})),
707
+ ...callListeners(EventType.PERSIST_STATE, { isMigrating: true }),
697
708
  // `migrating` to pause Apify crawlers
698
- ...serviceLocator
699
- .getEventManager()
700
- .listeners(EventType.MIGRATING)
701
- .map(async (x) => x({})),
702
- ]);
709
+ ...callListeners(EventType.MIGRATING, {}),
710
+ ]), timeoutSecs * 1000, `Pre-reboot event listeners did not finish within ${timeoutSecs} seconds, proceeding with the reboot`).catch((err) => log.warning(err.message));
703
711
  const runId = this.configuration.actorRunId;
704
- await this.apifyClient.run(runId).reboot();
712
+ try {
713
+ await this.apifyClient.run(runId).reboot();
714
+ }
715
+ catch (err) {
716
+ // Reset the flag so that a failed reboot can be retried.
717
+ this.#isRebooting = false;
718
+ throw err;
719
+ }
705
720
  // Wait some time for container to be stopped.
706
- const { customAfterSleepMillis = this.configuration.metamorphAfterSleepMillis } = options;
707
721
  await sleep(customAfterSleepMillis);
708
722
  }
709
723
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify",
3
- "version": "4.0.0-beta.106",
3
+ "version": "4.0.0-beta.107",
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": ">=22.13.0"