Skip to content

Commit 71303b8

Browse files
Cancel run in the UI when CLI fails (#1102)
## Changes When CLI fails before we have a run ID, the UI still remains in the running state until timeout. We need to move the UI to the errored/cancelled state when terminal is killed or the CLI errors. ## Tests <!-- How is this tested? -->
1 parent f0986e1 commit 71303b8

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

packages/databricks-vscode/src/bundle/run/BundleRunStatusManager.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,20 @@ export class BundleRunStatusManager implements Disposable {
9393
})
9494
);
9595
this.onDidChangeEmitter.fire();
96-
await this.bundleRunTerminalManager.run(resourceKey, (data) => {
97-
remoteRunStatus.parseId(data);
98-
});
96+
await this.bundleRunTerminalManager.run(
97+
resourceKey,
98+
(data) => {
99+
remoteRunStatus.parseId(data);
100+
},
101+
async (exitCode) => {
102+
await remoteRunStatus.cancel();
103+
if (exitCode !== 0) {
104+
remoteRunStatus.runState = "error";
105+
} else {
106+
remoteRunStatus.runState = "cancelled";
107+
}
108+
}
109+
);
99110
}
100111

101112
async cancel(resourceKey: string) {

packages/databricks-vscode/src/bundle/run/BundleRunTerminalManager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export class BundleRunTerminalManager implements Disposable {
2323
return `Run ${resourceKey} (${target})`;
2424
}
2525

26-
async run(resourceKey: string, onDidUpdate?: (data: string) => void) {
26+
async run(
27+
resourceKey: string,
28+
onDidUpdate?: (data: string) => void,
29+
onDidClose?: (code: number | null) => void
30+
) {
2731
const target = this.bundleRemoteStateModel.target;
2832
if (target === undefined) {
2933
throw new Error(`Cannot run ${resourceKey}, Target is undefined`);
@@ -88,6 +92,7 @@ export class BundleRunTerminalManager implements Disposable {
8892
return;
8993
}
9094
terminal.pty.onDidCloseProcess((exitCode) => {
95+
onDidClose?.(exitCode);
9196
if (exitCode === 0 || terminal.pty.isClosed) {
9297
// Resolve when the process exits with code 0 or is closed by human action
9398
resolve();

packages/databricks-vscode/src/ui/bundle-resource-explorer/BundleCommands.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ export class BundleCommands implements Disposable {
5353
if (!(e instanceof Error)) {
5454
throw e;
5555
}
56-
const choice = await window.showErrorMessage(
57-
"Error refreshing bundle state.",
58-
"Show Logs"
59-
);
60-
if (choice === "Show Logs") {
61-
commands.executeCommand("databricks.bundle.showLogs");
62-
}
56+
window
57+
.showErrorMessage("Error refreshing bundle state.", "Show Logs")
58+
.then((choice) => {
59+
if (choice === "Show Logs") {
60+
commands.executeCommand("databricks.bundle.showLogs");
61+
}
62+
});
6363
throw e;
6464
}
6565
}
@@ -87,13 +87,13 @@ export class BundleCommands implements Disposable {
8787
if (!(e instanceof Error)) {
8888
throw e;
8989
}
90-
const choice = await window.showErrorMessage(
91-
"Error deploying resource.",
92-
"Show Logs"
93-
);
94-
if (choice === "Show Logs") {
95-
commands.executeCommand("databricks.bundle.showLogs");
96-
}
90+
window
91+
.showErrorMessage("Error deploying resource.", "Show Logs")
92+
.then((choice) => {
93+
if (choice === "Show Logs") {
94+
commands.executeCommand("databricks.bundle.showLogs");
95+
}
96+
});
9797
throw e;
9898
} finally {
9999
this.whenContext.setDeploymentState("idle");

0 commit comments

Comments
 (0)