Skip to content

Commit

Permalink
Cancel workflow run if the webview panel is closed before the run eve…
Browse files Browse the repository at this point in the history
…n started (#1365)

## Changes
Cancel workflow run if the webview panel is closed before the run even
started

## Tests
Manually
  • Loading branch information
ilia-db authored Sep 19, 2024
1 parent e51e62b commit d090ec7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/databricks-vscode/src/run/WorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.",
Expand Down Expand Up @@ -159,7 +162,7 @@ export class WorkflowRunner implements Disposable {
) => {
panel.updateState(cluster, state, run);
},
token: cancellation.token,
token: panelCancellation.token,
})
);
} else {
Expand All @@ -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 || "");
Expand Down

0 comments on commit d090ec7

Please sign in to comment.