From 344e2e5a4494ac69b170a8953f59576a2f63def6 Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Fri, 2 May 2025 14:59:16 +0100 Subject: [PATCH] better debug logs --- .../cli-v3/src/entryPoints/managed/execution.ts | 10 ++++------ packages/cli-v3/src/entryPoints/managed/poller.ts | 14 +++++++++----- .../src/entryPoints/managed/snapshot.test.ts | 4 ++-- .../cli-v3/src/entryPoints/managed/snapshot.ts | 6 ++++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/cli-v3/src/entryPoints/managed/execution.ts b/packages/cli-v3/src/entryPoints/managed/execution.ts index fb42773fd..d0726d726 100644 --- a/packages/cli-v3/src/entryPoints/managed/execution.ts +++ b/packages/cli-v3/src/entryPoints/managed/execution.ts @@ -443,9 +443,7 @@ export class RunExecution { logger: this.logger, snapshotPollIntervalSeconds: this.env.TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS, handleSnapshotChange: this.enqueueSnapshotChangeAndWait.bind(this), - }); - - this.snapshotPoller.start(); + }).start(); const [startError, start] = await tryCatch( this.startAttempt({ isWarmStart: runOpts.isWarmStart }) @@ -500,7 +498,7 @@ export class RunExecution { } if (executeError instanceof SuspendedProcessError) { - this.sendDebugLog("run was suspended", { + this.sendDebugLog("execution was suspended", { run: run.friendlyId, snapshot: snapshot.friendlyId, error: executeError.message, @@ -510,7 +508,7 @@ export class RunExecution { } if (executeError instanceof ExecutionAbortError) { - this.sendDebugLog("run was interrupted", { + this.sendDebugLog("execution was aborted", { run: run.friendlyId, snapshot: snapshot.friendlyId, error: executeError.message, @@ -981,7 +979,7 @@ export class RunExecution { this.shutdownReason = reason; this.snapshotPoller?.stop(); - this.snapshotManager?.cleanup(); + this.snapshotManager?.dispose(); this.taskRunProcess?.unsafeDetachEvtHandlers(); } diff --git a/packages/cli-v3/src/entryPoints/managed/poller.ts b/packages/cli-v3/src/entryPoints/managed/poller.ts index 31b04be4c..fb4c5fb8f 100644 --- a/packages/cli-v3/src/entryPoints/managed/poller.ts +++ b/packages/cli-v3/src/entryPoints/managed/poller.ts @@ -63,8 +63,6 @@ export class RunExecutionSnapshotPoller { }); }, }); - - this.sendDebugLog("created"); } private sendDebugLog(message: string, properties?: SendDebugLogOptions["properties"]) { @@ -93,14 +91,18 @@ export class RunExecutionSnapshotPoller { this.poller.updateInterval(intervalMs); } - start() { + start(): RunExecutionSnapshotPoller { if (this.enabled) { this.sendDebugLog("already started"); - return; + return this; } + this.sendDebugLog("start"); + this.enabled = true; this.poller.start(); + + return this; } stop() { @@ -109,12 +111,14 @@ export class RunExecutionSnapshotPoller { return; } + this.sendDebugLog("stop"); + this.enabled = false; const { isExecuting } = this.poller.stop(); if (isExecuting) { - this.sendDebugLog("stopped poller but it's still executing"); + this.sendDebugLog("stopped while executing"); } } } diff --git a/packages/cli-v3/src/entryPoints/managed/snapshot.test.ts b/packages/cli-v3/src/entryPoints/managed/snapshot.test.ts index 256db83cf..1efd0de6c 100644 --- a/packages/cli-v3/src/entryPoints/managed/snapshot.test.ts +++ b/packages/cli-v3/src/entryPoints/managed/snapshot.test.ts @@ -306,8 +306,8 @@ describe("SnapshotManager", () => { expect(manager.queueLength).not.toBe(0); - // Call cleanup before they complete - manager.cleanup(); + // Dispose manager before any promises complete + manager.dispose(); expect(manager.queueLength).toBe(0); diff --git a/packages/cli-v3/src/entryPoints/managed/snapshot.ts b/packages/cli-v3/src/entryPoints/managed/snapshot.ts index ce8b5ad3e..f109db17d 100644 --- a/packages/cli-v3/src/entryPoints/managed/snapshot.ts +++ b/packages/cli-v3/src/entryPoints/managed/snapshot.ts @@ -286,10 +286,12 @@ export class SnapshotManager { } } - public cleanup() { + public dispose() { + this.sendDebugLog("dispose"); + // Clear any pending changes for (const item of this.changeQueue) { - item.reject(new Error("SnapshotManager cleanup")); + item.reject(new Error("SnapshotManager disposed")); } this.changeQueue = []; }