-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathdeleteTaskHub.ts
More file actions
58 lines (50 loc) · 2.58 KB
/
deleteTaskHub.ts
File metadata and controls
58 lines (50 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import {type IActionContext } from "@microsoft/vscode-azext-utils";
import { type DurableTaskSchedulerClient } from "../../tree/durableTaskScheduler/DurableTaskSchedulerClient";
import { localize } from "../../localize";
import { type DurableTaskHubResourceModel } from "../../tree/durableTaskScheduler/DurableTaskHubResourceModel";
import { commands, type MessageItem } from "vscode";
import { withAzureActivity } from "../../utils/AzureActivity";
import { withCancellation } from "../../utils/cancellation";
export function deleteTaskHubCommandFactory(schedulerClient: DurableTaskSchedulerClient) {
return async (actionContext: IActionContext, taskHub: DurableTaskHubResourceModel | undefined): Promise<void> => {
if (!taskHub) {
throw new Error(localize('noTaskHubSelectedErrorMessage', 'No task hub was selected.'));
}
const deleteItem: MessageItem = {
title: localize('deleteTaskHubLabel', 'Delete')
};
const result = await actionContext.ui.showWarningMessage(
localize('deleteTaskHubConfirmationMessage', 'Are you sure you want to delete task hub \'{0}\'?', taskHub.name),
{
modal: true
},
deleteItem
);
if (result !== deleteItem) {
return;
}
try {
await withAzureActivity(
localize('deletingTaskHubActivityLabel', 'Delete Durable Task Hub \'{0}\'', taskHub.name),
async () => {
const response = await schedulerClient.deleteTaskHub(
taskHub.scheduler.subscription,
taskHub.scheduler.resourceGroup,
taskHub.scheduler.name,
taskHub.name);
const result = await withCancellation(token => response.waitForCompletion(token), 1000 * 60 * 5);
if (result !== true) {
throw new Error(localize('deleteFailureMessage', 'The scheduler failed to delete within the allotted time.'));
}
});
}
finally {
taskHub.scheduler.refresh();
await commands.executeCommand('azureResourceGroups.refresh');
}
};
}