Skip to content

Commit

Permalink
Cancel run in the UI when CLI fails (#1102)
Browse files Browse the repository at this point in the history
## 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? -->
  • Loading branch information
kartikgupta-db authored Mar 5, 2024
1 parent f0986e1 commit 71303b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,20 @@ export class BundleRunStatusManager implements Disposable {
})
);
this.onDidChangeEmitter.fire();
await this.bundleRunTerminalManager.run(resourceKey, (data) => {
remoteRunStatus.parseId(data);
});
await this.bundleRunTerminalManager.run(
resourceKey,
(data) => {
remoteRunStatus.parseId(data);
},
async (exitCode) => {
await remoteRunStatus.cancel();
if (exitCode !== 0) {
remoteRunStatus.runState = "error";
} else {
remoteRunStatus.runState = "cancelled";
}
}
);
}

async cancel(resourceKey: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export class BundleRunTerminalManager implements Disposable {
return `Run ${resourceKey} (${target})`;
}

async run(resourceKey: string, onDidUpdate?: (data: string) => void) {
async run(
resourceKey: string,
onDidUpdate?: (data: string) => void,
onDidClose?: (code: number | null) => void
) {
const target = this.bundleRemoteStateModel.target;
if (target === undefined) {
throw new Error(`Cannot run ${resourceKey}, Target is undefined`);
Expand Down Expand Up @@ -88,6 +92,7 @@ export class BundleRunTerminalManager implements Disposable {
return;
}
terminal.pty.onDidCloseProcess((exitCode) => {
onDidClose?.(exitCode);
if (exitCode === 0 || terminal.pty.isClosed) {
// Resolve when the process exits with code 0 or is closed by human action
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export class BundleCommands implements Disposable {
if (!(e instanceof Error)) {
throw e;
}
const choice = await window.showErrorMessage(
"Error refreshing bundle state.",
"Show Logs"
);
if (choice === "Show Logs") {
commands.executeCommand("databricks.bundle.showLogs");
}
window
.showErrorMessage("Error refreshing bundle state.", "Show Logs")
.then((choice) => {
if (choice === "Show Logs") {
commands.executeCommand("databricks.bundle.showLogs");
}
});
throw e;
}
}
Expand Down Expand Up @@ -87,13 +87,13 @@ export class BundleCommands implements Disposable {
if (!(e instanceof Error)) {
throw e;
}
const choice = await window.showErrorMessage(
"Error deploying resource.",
"Show Logs"
);
if (choice === "Show Logs") {
commands.executeCommand("databricks.bundle.showLogs");
}
window
.showErrorMessage("Error deploying resource.", "Show Logs")
.then((choice) => {
if (choice === "Show Logs") {
commands.executeCommand("databricks.bundle.showLogs");
}
});
throw e;
} finally {
this.whenContext.setDeploymentState("idle");
Expand Down

0 comments on commit 71303b8

Please sign in to comment.