@@ -32,6 +32,7 @@ internal class RequestProcessor
32
32
private readonly PowerShellManagerPool _powershellPool ;
33
33
private DependencyManager _dependencyManager ;
34
34
private string _pwshVersion ;
35
+ private string _functionAppRootPath ;
35
36
36
37
// Holds the exception if an issue is encountered while processing the function app dependencies.
37
38
private Exception _initTerminatingError ;
@@ -135,18 +136,6 @@ internal StreamingMessage ProcessWorkerInitRequest(StreamingMessage request)
135
136
136
137
response . WorkerInitResponse . WorkerMetadata = GetWorkerMetadata ( _pwshVersion ) ;
137
138
138
- // Previously, the dependency management would happen just prior to the dependency download in the
139
- // first function load request. Now that we have the FunctionAppDirectory in the WorkerInitRequest,
140
- // we can do the setup of these variables in the function load request. We need these variables initialized
141
- // for the FunctionMetadataRequest, should it be sent.
142
- _dependencyManager = new DependencyManager ( request . WorkerInitRequest . FunctionAppDirectory , logger : rpcLogger ) ;
143
-
144
- // The profile is invoke during this stage.
145
- // TODO: Initialize the first PowerShell instance, but delay the invocation of the profile.
146
- // The first PowerShell instance will be used to import the PowerShell SDK to generate the function metadata
147
- // Issue: We do not know if Managed Dependencies is enabled until the first function load.
148
- _powershellPool . Initialize ( _firstPwshInstance ) ;
149
-
150
139
rpcLogger . Log ( isUserOnlyLog : false , LogLevel . Trace , string . Format ( PowerShellWorkerStrings . WorkerInitCompleted , stopwatch . ElapsedMilliseconds ) ) ;
151
140
}
152
141
catch ( Exception e )
@@ -231,16 +220,39 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
231
220
{
232
221
try
233
222
{
223
+ _isFunctionAppInitialized = true ;
224
+
234
225
var rpcLogger = new RpcLogger ( _msgStream ) ;
235
226
rpcLogger . SetContext ( request . RequestId , null ) ;
236
227
237
- _isFunctionAppInitialized = true ;
228
+ // _functionAppRootPath is set in ProcessFunctionMetadataRequest for the v2 progamming model.
229
+ if ( _functionAppRootPath == null )
230
+ {
231
+ // If _functionAppRootPath is null, this means that this is an app for the v1 programming model.
232
+ _functionAppRootPath = request . FunctionLoadRequest . Metadata . Directory ;
233
+ }
238
234
235
+ if ( string . IsNullOrWhiteSpace ( _functionAppRootPath ) )
236
+ {
237
+ throw new ArgumentException ( "Failed to resolve the function app root" , nameof ( _functionAppRootPath ) ) ;
238
+ }
239
+
240
+ _dependencyManager = new DependencyManager ( _functionAppRootPath , logger : rpcLogger ) ;
239
241
var managedDependenciesPath = _dependencyManager . Initialize ( request , rpcLogger ) ;
240
242
241
- SetupAppRootPathAndModulePath ( request . FunctionLoadRequest , managedDependenciesPath ) ;
243
+ SetupAppRootPathAndModulePath ( _functionAppRootPath , managedDependenciesPath ) ;
244
+
245
+ // The profile is invoke when the instance is initialized.
246
+ // TODO: Initialize the first PowerShell instance but delay the invocation of the profile until the first function load.
247
+ // The first PowerShell instance will be used to import the AzureFunctions.PowerShell.SDK to generate the function metadata
248
+ // Issue: We do not know if Managed Dependencies is enabled until the first function load.
249
+ _powershellPool . Initialize ( _firstPwshInstance ) ;
250
+
242
251
// Start the download asynchronously if needed.
243
252
_dependencyManager . StartDependencyInstallationIfNeeded ( request , _firstPwshInstance , rpcLogger ) ;
253
+
254
+ rpcLogger . Log ( isUserOnlyLog : false , LogLevel . Trace , string . Format ( PowerShellWorkerStrings . FirstFunctionLoadCompleted , stopwatch . ElapsedMilliseconds ) ) ;
255
+
244
256
}
245
257
catch ( Exception e )
246
258
{
@@ -387,8 +399,8 @@ private StreamingMessage ProcessFunctionMetadataRequest(StreamingMessage request
387
399
var rpcLogger = new RpcLogger ( _msgStream ) ;
388
400
rpcLogger . SetContext ( request . RequestId , null ) ;
389
401
390
- //response.FunctionMetadataResponse.FunctionMetadataResults.AddRange(WorkerIndexingHelper.IndexFunctions( request.FunctionsMetadataRequest.FunctionAppDirectory)) ;
391
- response . FunctionMetadataResponse . FunctionMetadataResults . AddRange ( WorkerIndexingHelper . IndexFunctions ( request . FunctionsMetadataRequest . FunctionAppDirectory , rpcLogger ) ) ;
402
+ _functionAppRootPath = request . FunctionsMetadataRequest . FunctionAppDirectory ;
403
+ response . FunctionMetadataResponse . FunctionMetadataResults . AddRange ( WorkerIndexingHelper . IndexFunctions ( _functionAppRootPath , rpcLogger ) ) ;
392
404
393
405
return response ;
394
406
}
@@ -559,9 +571,9 @@ private static void BindOutputFromResult(InvocationResponse response, AzFunction
559
571
}
560
572
}
561
573
562
- private void SetupAppRootPathAndModulePath ( FunctionLoadRequest functionLoadRequest , string managedDependenciesPath )
574
+ private void SetupAppRootPathAndModulePath ( string functionAppRootPath , string managedDependenciesPath )
563
575
{
564
- FunctionLoader . SetupWellKnownPaths ( functionLoadRequest , managedDependenciesPath ) ;
576
+ FunctionLoader . SetupWellKnownPaths ( functionAppRootPath , managedDependenciesPath ) ;
565
577
566
578
if ( FunctionLoader . FunctionAppRootPath == null )
567
579
{
0 commit comments