@@ -7,11 +7,12 @@ import type { StringDictionary } from '@azure/arm-appservice';
77import type { ParsedSite } from '@microsoft/vscode-azext-azureappservice' ;
88import { IActionContext } from '@microsoft/vscode-azext-utils' ;
99import * as vscode from 'vscode' ;
10- import { ConnectionKey , ConnectionKeyValues , DurableBackend , DurableBackendValues , extensionVersionKey , ProjectLanguage , runFromPackageKey , workerRuntimeKey } from '../../constants' ;
10+ import { azureWebJobsFeatureFlags , ConnectionKey , ConnectionKeyValues , DurableBackend , DurableBackendValues , extensionVersionKey , ProjectLanguage , runFromPackageKey , workerRuntimeKey } from '../../constants' ;
1111import { ext } from '../../extensionVariables' ;
1212import { FuncVersion , tryParseFuncVersion } from '../../FuncVersion' ;
1313import { localize } from '../../localize' ;
1414import { SlotTreeItem } from '../../tree/SlotTreeItem' ;
15+ import { isNodeV4Plus , isPythonV2Plus } from '../../utils/programmingModelUtils' ;
1516import { isKnownWorkerRuntime , promptToUpdateDotnetRuntime , tryGetFunctionsWorkerRuntimeForProject } from '../../vsCodeConfig/settings' ;
1617import { ISetConnectionSettingContext } from '../appSettings/connectionSettings/ISetConnectionSettingContext' ;
1718
@@ -20,7 +21,18 @@ import { ISetConnectionSettingContext } from '../appSettings/connectionSettings/
2021 */
2122type VerifyAppSettingBooleans = { doRemoteBuild : boolean | undefined ; isConsumption : boolean } ;
2223
23- export async function verifyAppSettings ( context : IActionContext , node : SlotTreeItem , projectPath : string | undefined , version : FuncVersion , language : ProjectLanguage , bools : VerifyAppSettingBooleans , durableStorageType : DurableBackendValues | undefined ) : Promise < void > {
24+ export async function verifyAppSettings ( options : {
25+ context : IActionContext ,
26+ node : SlotTreeItem ,
27+ projectPath : string | undefined ,
28+ version : FuncVersion ,
29+ language : ProjectLanguage ,
30+ languageModel : number | undefined ,
31+ bools : VerifyAppSettingBooleans ,
32+ durableStorageType : DurableBackendValues | undefined
33+ } ) : Promise < void > {
34+
35+ const { context, node, projectPath, version, language, bools, durableStorageType } = options ;
2436 const client = await node . site . createClient ( context ) ;
2537 const appSettings : StringDictionary = await client . listApplicationSettings ( ) ;
2638 if ( appSettings . properties ) {
@@ -36,6 +48,10 @@ export async function verifyAppSettings(context: IActionContext, node: SlotTreeI
3648 updateAppSettings ||= verifyRunFromPackage ( context , node . site , appSettings . properties ) ;
3749 }
3850
51+ if ( isNodeV4Plus ( options ) || isPythonV2Plus ( options . language , options . languageModel ) ) {
52+ updateAppSettings ||= verifyFeatureFlagSetting ( context , node . site , appSettings . properties ) ;
53+ }
54+
3955 const updatedRemoteConnection : boolean = await verifyAndUpdateAppConnectionStrings ( context , durableStorageType , appSettings . properties ) ;
4056 updateAppSettings ||= updatedRemoteConnection ;
4157
@@ -168,3 +184,21 @@ function verifyLinuxRemoteBuildSettings(context: IActionContext, remotePropertie
168184 return hasChanged ;
169185}
170186
187+ function verifyFeatureFlagSetting ( context : IActionContext , site : ParsedSite , remoteProperties : { [ propertyName : string ] : string } ) : boolean {
188+ const featureFlagString = remoteProperties [ azureWebJobsFeatureFlags ] || '' ;
189+
190+ // Feature flags are comma-delimited lists of beta features
191+ // https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobsfeatureflags
192+ const featureFlagArray = ! featureFlagString ? [ ] : featureFlagString . split ( ',' ) ;
193+ const enableWorkerIndexingValue = 'EnableWorkerIndexing' ;
194+ const shouldAddSetting : boolean = ! featureFlagArray . includes ( enableWorkerIndexingValue ) ;
195+
196+ if ( shouldAddSetting ) {
197+ featureFlagArray . push ( enableWorkerIndexingValue ) ;
198+ ext . outputChannel . appendLog ( localize ( 'addedFeatureFlag' , 'Added feature flag "{0}" because it is required for the new programming model' , enableWorkerIndexingValue ) , { resourceName : site . fullName } ) ;
199+ remoteProperties [ azureWebJobsFeatureFlags ] = featureFlagArray . join ( ',' ) ;
200+ }
201+
202+ context . telemetry . properties . addedFeatureFlagSetting = String ( shouldAddSetting ) ;
203+ return shouldAddSetting ;
204+ }
0 commit comments