using promise.all() when upload files (#108)

* using promise.all() when upload files

* add promise all
This commit is contained in:
Sheng Chen 2018-02-09 13:50:57 +08:00 коммит произвёл GitHub
Родитель eb81f07e70
Коммит 09485fbd0a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 24 добавлений и 18 удалений

Просмотреть файл

@ -13,34 +13,28 @@ import { delay } from "./cloudConsoleLauncher";
import { aciConfig, Constants, exportContainerCmd, exportTestScript } from "./constants";
import { azFilePush, escapeFile, TerminalType, TestOption, TFTerminal } from "./shared";
import { terraformChannel } from "./terraformChannel";
import { DialogOption } from "./utils/uiUtils";
import { DialogOption, DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
const tempFile = path.join(os.tmpdir(), "cloudshell" + vscode.env.sessionId + ".log");
export class CloudShell extends BaseShell {
public async pushFiles(files: vscode.Uri[], syncAllFiles: boolean): Promise<void> {
public async pushFiles(files: vscode.Uri[]): Promise<void> {
terraformChannel.appendLine("Attempting to upload files to CloudShell...");
if (await this.connectedToCloudShell()) {
const promises: Array<Promise<void>> = [];
for (const file of files.map((a) => a.fsPath)) {
try {
if (await fsExtra.pathExists(file)) {
terraformChannel.appendLine(`Uploading file ${file} to cloud shell`);
await azFilePush(
vscode.workspace.getWorkspaceFolder(vscode.Uri.file(file)).name,
this.tfTerminal.storageAccountName,
this.tfTerminal.storageAccountKey,
this.tfTerminal.fileShareName, file);
}
} catch (err) {
terraformChannel.appendLine(err);
}
promises.push(this.pushFilePromise(file));
}
if (syncAllFiles) {
vscode.window.showInformationMessage(
"Synced all matched files in the current workspace to CloudShell");
try {
await Promise.all(promises);
vscode.window.showInformationMessage("Synced all matched files in the current workspace to CloudShell");
} catch (error) {
terraformChannel.appendLine(error);
await promptForOpenOutputChannel("Failed to push files to the cloud. Please open the output channel for more details.", DialogType.error);
}
}
}
@ -154,7 +148,19 @@ export class CloudShell extends BaseShell {
console.log("Open CloudShell cancelled by user.");
return false;
}
private async pushFilePromise(file: string): Promise<void> {
if (await fsExtra.pathExists(file)) {
terraformChannel.appendLine(`Uploading file ${file} to cloud shell`);
await azFilePush(
vscode.workspace.getWorkspaceFolder(vscode.Uri.file(file)).name,
this.tfTerminal.storageAccountName,
this.tfTerminal.storageAccountKey,
this.tfTerminal.fileShareName,
file,
);
}
}
private async resolveContainerCmd(TestType: string): Promise<string> {

Просмотреть файл

@ -78,7 +78,7 @@ export function activate(ctx: vscode.ExtensionContext) {
// Create a function that will sync the files to Cloudshell
if (terminalSetToCloudshell()) {
vscode.workspace.findFiles(filesGlobSetting()).then((tfFiles) => {
cs.pushFiles(tfFiles, true);
cs.pushFiles(tfFiles);
});
} else {
vscode.window.showErrorMessage("Push function only available when using cloudshell.");