Skip to content

Commit

Permalink
fix: use correct event manager for actor methods (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu authored Aug 26, 2022
1 parent 82937dd commit ef3a0c5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/apify/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ export class Actor<Data extends Dictionary = Dictionary> {
// reset global config instance to respect APIFY_ prefixed env vars
CoreConfiguration.globalConfig = Configuration.getGlobalConfig();

await this.eventManager.init();

if (this.isAtHome()) {
this.config.set('availableMemoryRatio', 1);
this.config.set('disableBrowserSandbox', true); // for browser launcher, adds `--no-sandbox` to args
Expand All @@ -179,6 +177,9 @@ export class Actor<Data extends Dictionary = Dictionary> {
this.config.useStorageClient(options.storage);
}

// Init the event manager the config uses
await this.config.getEventManager().init();

await purgeDefaultStorages(this.config);
Configuration.storage.enterWith(this.config);
}
Expand All @@ -193,15 +194,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
options.timeoutSecs ??= 30;

// Close the event manager and emit the final PERSIST_STATE event
await this.eventManager.close();
await this.config.getEventManager().close();

// Emit the exit event
this.eventManager.emit(EventType.EXIT, options);
this.config.getEventManager().emit(EventType.EXIT, options);

// Wait for all event listeners to be processed
log.debug(`Waiting for all event listeners to complete their execution (with ${options.timeoutSecs} seconds timeout)`);
await addTimeoutToPromise(
() => this.eventManager.waitForAllListenersToComplete(),
() => this.config.getEventManager().waitForAllListenersToComplete(),
options.timeoutSecs * 1000,
`Waiting for all event listeners to complete their execution timed out after ${options.timeoutSecs} seconds`,
);
Expand Down Expand Up @@ -245,14 +246,14 @@ export class Actor<Data extends Dictionary = Dictionary> {
* @ignore
*/
on(event: EventTypeName, listener: (...args: any[]) => any): void {
this.eventManager.on(event, listener);
this.config.getEventManager().on(event, listener);
}

/**
* @ignore
*/
off(event: EventTypeName, listener?: (...args: any[]) => any): void {
this.eventManager.off(event, listener);
this.config.getEventManager().off(event, listener);
}

/**
Expand Down

0 comments on commit ef3a0c5

Please sign in to comment.