From d090ec72cc4bd609830d453748cfa4fd7700a39f Mon Sep 17 00:00:00 2001 From: Ilia Babanov Date: Thu, 19 Sep 2024 12:48:44 +0200 Subject: [PATCH] Cancel workflow run if the webview panel is closed before the run even started (#1365) ## Changes Cancel workflow run if the webview panel is closed before the run even started ## Tests Manually --- .../databricks-vscode/src/run/WorkflowRunner.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/databricks-vscode/src/run/WorkflowRunner.ts b/packages/databricks-vscode/src/run/WorkflowRunner.ts index 69d8f507e..1d65ae2b6 100644 --- a/packages/databricks-vscode/src/run/WorkflowRunner.ts +++ b/packages/databricks-vscode/src/run/WorkflowRunner.ts @@ -81,13 +81,11 @@ export class WorkflowRunner implements Disposable { }) { const panel = await this.getPanelForUri(program.uri); - const cancellation = new CancellationTokenSource(); - panel.onDidDispose(() => cancellation.cancel()); + const panelCancellation = new CancellationTokenSource(); + panel.onDidDispose(() => panelCancellation.cancel()); if (token) { - token.onCancellationRequested(() => { - cancellation.cancel(); - }); + token.onCancellationRequested(() => panelCancellation.cancel()); } try { @@ -100,6 +98,11 @@ export class WorkflowRunner implements Disposable { } return; } + + if (panelCancellation.token.isCancellationRequested) { + return; + } + if (token?.isCancellationRequested) { panel.showError({ message: "Execution terminated by user.", @@ -159,7 +162,7 @@ export class WorkflowRunner implements Disposable { ) => { panel.updateState(cluster, state, run); }, - token: cancellation.token, + token: panelCancellation.token, }) ); } else { @@ -184,7 +187,7 @@ export class WorkflowRunner implements Disposable { ) => { panel.updateState(cluster, state, run); }, - token: cancellation.token, + token: panelCancellation.token, }); //TODO: Respone logs will contain bootstrap code path in the error stack trace. Remove it. panel.showStdoutResult(response.logs || "");