Add return to Build ACR Command (#3695)

* add return

* address feedback

* fix formatting

* add extra enum checks
This commit is contained in:
Oliver King 2022-11-11 16:42:05 -05:00 коммит произвёл GitHub
Родитель b416f6446a
Коммит 38e47775b1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 29 добавлений и 4 удалений

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

@ -5,12 +5,33 @@
import * as vscode from 'vscode';
import { IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
import type { Run } from '@azure/arm-containerregistry';
import { scheduleRunRequest } from './scheduleRunRequest';
import { delay } from '../../../../utils/promiseUtils';
import { getArmContainerRegistry } from '../../../../utils/lazyPackages';
export async function buildImageInAzure(context: IActionContext, uri?: vscode.Uri | undefined): Promise<void> {
const WAIT_MS = 5000;
export async function buildImageInAzure(context: IActionContext, uri?: vscode.Uri | undefined): Promise<Run | undefined> {
if (!vscode.workspace.isTrusted) {
throw new UserCancelledError('enforceTrust');
}
await scheduleRunRequest(context, "DockerBuildRequest", uri);
const getRun = await scheduleRunRequest(context, "DockerBuildRequest", uri);
let run = await getRun();
const { KnownRunStatus } = await getArmContainerRegistry();
while (
run.status === KnownRunStatus.Started ||
run.status === KnownRunStatus.Queued ||
run.status === KnownRunStatus.Running
) {
await delay(WAIT_MS);
run = await getRun();
}
// we are returning the run so that other extensions can consume this with the vscode.commands.executeCommand
// currently it is used by the ms-kubernetes-tools.aks-devx-tools extension (https://github.com/Azure/aks-devx-tools)
return run;
}

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

@ -24,7 +24,7 @@ import { getStorageBlob } from '../../../../utils/lazyPackages';
const idPrecision = 6;
const vcsIgnoreList = ['.git', '.gitignore', '.bzr', 'bzrignore', '.hg', '.hgignore', '.svn'];
export async function scheduleRunRequest(context: IActionContext, requestType: 'DockerBuildRequest' | 'FileTaskRunRequest', uri: vscode.Uri | undefined): Promise<void> {
export async function scheduleRunRequest(context: IActionContext, requestType: 'DockerBuildRequest' | 'FileTaskRunRequest', uri: vscode.Uri | undefined): Promise<() => Promise<AcrRun>> {
// Acquire information.
let rootFolder: vscode.WorkspaceFolder;
let fileItem: Item;
@ -76,10 +76,14 @@ export async function scheduleRunRequest(context: IActionContext, requestType: '
// Schedule the run and Clean up.
ext.outputChannel.appendLine(localize('vscode-docker.commands.registries.azure.tasks.setUp', 'Set up run request'));
const run = await (await node.getClient(context)).registries.beginScheduleRunAndWait(node.resourceGroup, node.registryName, runRequest);
const client = await node.getClient(context);
const run = await client.registries.beginScheduleRunAndWait(node.resourceGroup, node.registryName, runRequest);
ext.outputChannel.appendLine(localize('vscode-docker.commands.registries.azure.tasks.scheduledRun', 'Scheduled run {0}', run.runId));
void streamLogs(context, node, run);
// function returns the AcrRun info
return async () => client.runs.get(node.resourceGroup, node.registryName, run.runId);
} finally {
if (await fse.pathExists(tarFilePath)) {
await fse.unlink(tarFilePath);