notebook background execution (#8079)

* notebook background execution

* code review comments

* comments 2

* more logging
This commit is contained in:
Alan Ren
2019-10-29 11:53:50 -07:00
committed by GitHub
parent 6e7311ca87
commit 5629356c66
7 changed files with 83 additions and 20 deletions

View File

@@ -8,10 +8,12 @@ import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { DialogBase } from './dialogBase';
import { INotebookService } from '../services/notebookService';
import { DialogInfo, instanceOfNotebookBasedDialogInfo } from '../interfaces';
import { DialogInfo, instanceOfNotebookBasedDialogInfo, NotebookBasedDialogInfo } from '../interfaces';
import { Validator, initializeDialog, InputComponents, setModelValues } from './modelViewUtils';
import { Model } from './model';
import { EOL } from 'os';
import { getDateTimeString, getErrorMessage } from '../utils';
import { IPlatformService } from '../services/platformService';
const localize = nls.loadMessageBundle();
@@ -20,9 +22,19 @@ export class DeploymentInputDialog extends DialogBase {
private inputComponents: InputComponents = {};
constructor(private notebookService: INotebookService,
private platformService: IPlatformService,
private dialogInfo: DialogInfo) {
super(dialogInfo.title, dialogInfo.name, false);
this._dialogObject.okButton.label = localize('deploymentDialog.OKButtonText', "Open Notebook");
let okButtonText: string;
if (dialogInfo.actionText) {
okButtonText = dialogInfo.actionText;
} else if (instanceOfNotebookBasedDialogInfo(dialogInfo) && !dialogInfo.runNotebook) {
okButtonText = localize('deploymentDialog.OpenNotebook', "Open Notebook");
} else {
okButtonText = localize('deploymentDialog.OkButtonText', "OK");
}
this._dialogObject.okButton.label = okButtonText;
}
protected initialize() {
@@ -63,11 +75,52 @@ export class DeploymentInputDialog extends DialogBase {
setModelValues(this.inputComponents, model);
if (instanceOfNotebookBasedDialogInfo(this.dialogInfo)) {
model.setEnvironmentVariables();
this.notebookService.launchNotebook(this.dialogInfo.notebook).then(() => { }, (error) => {
vscode.window.showErrorMessage(error);
});
if (this.dialogInfo.runNotebook) {
this.executeNotebook(this.dialogInfo);
} else {
this.notebookService.launchNotebook(this.dialogInfo.notebook).then(() => { }, (error) => {
vscode.window.showErrorMessage(error);
});
}
} else {
vscode.commands.executeCommand(this.dialogInfo.command, model);
}
}
private executeNotebook(notebookDialogInfo: NotebookBasedDialogInfo): void {
azdata.tasks.startBackgroundOperation({
displayName: notebookDialogInfo.taskName!,
description: notebookDialogInfo.taskName!,
isCancelable: false,
operation: async op => {
op.updateStatus(azdata.TaskStatus.InProgress);
const notebook = await this.notebookService.getNotebook(notebookDialogInfo.notebook);
const result = await this.notebookService.executeNotebook(notebook);
if (result.succeeded) {
op.updateStatus(azdata.TaskStatus.Succeeded);
} else {
op.updateStatus(azdata.TaskStatus.Failed, result.errorMessage);
if (result.outputNotebook) {
const viewErrorDetail = localize('resourceDeployment.ViewErrorDetail', "View error detail");
const taskFailedMessage = localize('resourceDeployment.DeployFailed', "The task \"{0}\" has failed.", notebookDialogInfo.taskName);
const selectedOption = await vscode.window.showErrorMessage(taskFailedMessage, viewErrorDetail);
this.platformService.logToOutputChannel(taskFailedMessage);
if (selectedOption === viewErrorDetail) {
try {
this.notebookService.launchNotebookWithContent(`deploy-${getDateTimeString()}`, result.outputNotebook);
} catch (error) {
const launchNotebookError = localize('resourceDeployment.FailedToOpenNotebook', "An error occurred launching the output notebook. {1}{2}.", EOL, getErrorMessage(error));
this.platformService.logToOutputChannel(launchNotebookError);
vscode.window.showErrorMessage(launchNotebookError);
}
}
} else {
const errorMessage = localize('resourceDeployment.TaskFailedWithNoOutputNotebook', "The task \"{0}\" failed and no output Notebook was generated.", notebookDialogInfo.taskName);
this.platformService.logToOutputChannel(errorMessage);
vscode.window.showErrorMessage(errorMessage);
}
}
}
});
}
}