better debug logs

This commit is contained in:
nicktrn
2025-05-02 14:59:16 +01:00
parent 213a983202
commit 344e2e5a44
4 changed files with 19 additions and 15 deletions
@@ -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();
}
@@ -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");
}
}
}
@@ -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);
@@ -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 = [];
}