Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions src/commands/durableTaskScheduler/createScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type ResourceManagementClient } from '@azure/arm-resources';
import { type AzExtClientContext, createAzureClient, type ILocationWizardContext, type IResourceGroupWizardContext, LocationListStep, parseClientContext, ResourceGroupCreateStep, ResourceGroupListStep, VerifyProvidersStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, createSubscriptionContext, type ExecuteActivityContext, type IAzureQuickPickItem, type IActionContext, type ISubscriptionActionContext, subscriptionExperience } from "@microsoft/vscode-azext-utils";
import { AzureWizard, AzureWizardExecuteStepWithActivityOutput, AzureWizardPromptStep, createSubscriptionContext, type ExecuteActivityContext, type ExecuteActivityOutput, type IActionContext, type IAzureQuickPickItem, type ISubscriptionActionContext, subscriptionExperience } from "@microsoft/vscode-azext-utils";
import { type AzureSubscription } from "@microsoft/vscode-azureresources-api";
import { type Progress } from "vscode";
import { DurableTaskProvider, DurableTaskSchedulersResourceType } from "../../constants";
import { defaultDescription } from "../../constants-nls";
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { DurableTaskSchedulerSku, type DurableTaskSchedulerClient } from "../../tree/durableTaskScheduler/DurableTaskSchedulerClient";
import { type DurableTaskSchedulerClient, DurableTaskSchedulerSku } from "../../tree/durableTaskScheduler/DurableTaskSchedulerClient";
import { type DurableTaskSchedulerDataBranchProvider } from "../../tree/durableTaskScheduler/DurableTaskSchedulerDataBranchProvider";
import { createActivityContext } from "../../utils/activityUtils";
import { withCancellation } from "../../utils/cancellation";
import { type Progress } from "vscode";
import { type ResourceManagementClient } from '@azure/arm-resources';

interface ICreateSchedulerContext extends ISubscriptionActionContext, ILocationWizardContext, IResourceGroupWizardContext, ExecuteActivityContext {
subscription?: AzureSubscription;
schedulerSku?: DurableTaskSchedulerSku;
schedulerName?: string;
}

const schedulerNameRegex = /^[a-zA-Z0-9-]{3,64}$/;

class SchedulerNamingStep extends AzureWizardPromptStep<ICreateSchedulerContext> {
async prompt(wizardContext: ICreateSchedulerContext): Promise<void> {
wizardContext.schedulerName = await wizardContext.ui.showInputBox({
prompt: localize('schedulerNamingStepPrompt', 'Enter a name for the new scheduler')
prompt: localize('schedulerNamingStepPrompt', 'Enter a name for the new scheduler'),
validateInput: (value: string) => {
if (!schedulerNameRegex.test(value)) {
return localize('invalidSchedulerName', 'Name must be 3-64 characters and contain only letters, numbers, and hyphens.');
}
return undefined;
}
Comment thread
MicroFish91 marked this conversation as resolved.
Outdated
});
}

Expand All @@ -51,16 +59,30 @@ class SchedulerSkuStep extends AzureWizardPromptStep<ICreateSchedulerContext> {
}
}

class SchedulerCreationStep extends AzureWizardExecuteStep<ICreateSchedulerContext> {
priority: number = 1;
class SchedulerCreationStep extends AzureWizardExecuteStepWithActivityOutput<ICreateSchedulerContext> {
priority: number = 110;
readonly stepName: string = 'schedulerCreationStep';

protected getTreeItemLabel = (context: ICreateSchedulerContext) => localize('createSchedulerLabel', 'Create Durable Task Scheduler "{0}"', context.schedulerName);
protected getOutputLogSuccess = (context: ICreateSchedulerContext) => localize('createSchedulerSuccess', 'Successfully created Durable Task Scheduler "{0}".', context.schedulerName);
protected getOutputLogFail = (context: ICreateSchedulerContext) => localize('createSchedulerFail', 'Failed to create Durable Task Scheduler "{0}".', context.schedulerName);

public createProgressOutput(context: ICreateSchedulerContext): ExecuteActivityOutput {
const output = super.createProgressOutput(context);
if (output.item) {
output.item.description = localize('schedulerProgressDescription', 'This may take a while...');
}
return output;
}

constructor(private readonly schedulerClient: DurableTaskSchedulerClient) {
super();
}

async execute(wizardContext: ICreateSchedulerContext, _: Progress<{ message?: string; increment?: number; }>): Promise<void> {
const location = await LocationListStep.getLocation(wizardContext);
async execute(wizardContext: ICreateSchedulerContext, progress: Progress<{ message?: string; increment?: number; }>): Promise<void> {
progress.report({ message: localize('creatingScheduler', 'Creating Durable Task Scheduler...') });

const location = await LocationListStep.getLocation(wizardContext);
const response = await this.schedulerClient.createScheduler(
wizardContext.subscription as AzureSubscription,
wizardContext.resourceGroup?.name as string,
Expand Down Expand Up @@ -109,7 +131,7 @@ export function createSchedulerCommandFactory(dataBranchProvider: DurableTaskSch

...actionContext,
...createSubscriptionContext(subscription),
...await createActivityContext()
...await createActivityContext({ withChildren: true }),
};

if (!await isDtsProviderRegistered(wizardContext)) {
Expand Down
6 changes: 3 additions & 3 deletions src/tree/durableTaskScheduler/DurableTaskSchedulerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface DurableTaskSchedulerCreateRequest {
readonly ipAllowlist: string[];
readonly sku: {
readonly name: string;
readonly capacity: number;
readonly capacity?: number;
};
};
readonly tags: unknown;
Expand Down Expand Up @@ -95,7 +95,7 @@ export class HttpDurableTaskSchedulerClient implements DurableTaskSchedulerClien
ipAllowlist: ['0.0.0.0/0'],
sku: {
name: sku,
capacity: sku === DurableTaskSchedulerSku.Dedicated ? 1 : 0
...(sku === DurableTaskSchedulerSku.Dedicated ? { capacity: 1 } : {})
}
},
tags: {
Expand Down Expand Up @@ -187,7 +187,7 @@ export class HttpDurableTaskSchedulerClient implements DurableTaskSchedulerClien

private static getBaseUrl(subscription: AzureSubscription, resourceGroupName?: string, schedulerName?: string, relativeUrl?: string | undefined) {
const provider = 'Microsoft.DurableTask';
const apiVersion = '2024-10-01-preview';
const apiVersion = '2025-11-01';

let url = `${subscription.environment.resourceManagerEndpointUrl}subscriptions/${subscription.subscriptionId}`;

Expand Down
Loading