Skip to content

Commit b7e01fc

Browse files
authored
fix: add more logging to Actor.init and Actor.exit (#236)
1 parent cf9a6fd commit b7e01fc

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

packages/apify/src/actor.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
177177
*/
178178
async init(options: InitOptions = {}): Promise<void> {
179179
if (this.initialized) {
180+
log.debug(`Actor SDK was already initialized`);
180181
return;
181182
}
182183

@@ -207,11 +208,14 @@ export class Actor<Data extends Dictionary = Dictionary> {
207208

208209
// Init the event manager the config uses
209210
await this.config.getEventManager().init();
211+
log.debug(`Events initialized`);
210212

211213
await purgeDefaultStorages({
212214
config: this.config,
213215
onlyPurgeOnce: true,
214216
});
217+
log.debug(`Default storages purged`);
218+
215219
Configuration.storage.enterWith(this.config);
216220
}
217221

@@ -228,6 +232,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
228232

229233
// Close the event manager and emit the final PERSIST_STATE event
230234
await events.close();
235+
log.debug(`Events closed`);
231236

232237
// Emit the exit event
233238
events.emit(EventType.EXIT, options);
@@ -543,12 +548,25 @@ export class Actor<Data extends Dictionary = Dictionary> {
543548
break;
544549
}
545550

546-
const storageClient = this.config.getStorageClient();
547-
await storageClient.setStatusMessage?.(statusMessage, { isStatusMessageTerminal, level });
551+
const client = this.config.getStorageClient();
552+
553+
// just to be sure, this should be fast
554+
await addTimeoutToPromise(
555+
() => client.setStatusMessage!(statusMessage, { isStatusMessageTerminal, level }),
556+
1000,
557+
'Setting status message timed out after 1s',
558+
).catch((e) => log.warning(e.message));
548559

549560
const runId = this.config.get('actorRunId')!;
561+
550562
if (runId) {
551-
const run = await this.apifyClient.run(runId).get();
563+
// just to be sure, this should be fast
564+
const run = await addTimeoutToPromise(
565+
() => this.apifyClient.run(runId).get(),
566+
1000,
567+
'Getting the current run timed out after 1s',
568+
).catch((e) => log.warning(e.message));
569+
552570
if (run) {
553571
return run;
554572
}

0 commit comments

Comments
 (0)