7
7
using System . Linq ;
8
8
using System . Net . Http ;
9
9
using System . Threading . Tasks ;
10
+ using Azure ;
11
+ using Azure . Core ;
10
12
using Microsoft . AspNetCore . Http ;
11
13
using Microsoft . Azure . WebJobs . Script . Description ;
12
14
using Microsoft . Azure . WebJobs . Script . Management . Models ;
13
15
using Microsoft . Azure . WebJobs . Script . WebHost . Extensions ;
16
+ using Microsoft . Azure . WebJobs . Script . Workers . Rpc ;
17
+ using Microsoft . Extensions . DependencyInjection ;
14
18
using Microsoft . Extensions . Logging ;
15
19
using Microsoft . Extensions . Options ;
16
20
using Newtonsoft . Json ;
@@ -27,8 +31,11 @@ public class WebFunctionsManager : IWebFunctionsManager
27
31
private readonly IFunctionsSyncManager _functionsSyncManager ;
28
32
private readonly HostNameProvider _hostNameProvider ;
29
33
private readonly IFunctionMetadataManager _functionMetadataManager ;
34
+ private readonly IHostFunctionMetadataProvider _hostFunctionMetadataProvider ;
35
+ private readonly IOptionsMonitor < LanguageWorkerOptions > _languageWorkerOptions ;
30
36
31
- public WebFunctionsManager ( IOptionsMonitor < ScriptApplicationHostOptions > applicationHostOptions , ILoggerFactory loggerFactory , IHttpClientFactory httpClientFactory , ISecretManagerProvider secretManagerProvider , IFunctionsSyncManager functionsSyncManager , HostNameProvider hostNameProvider , IFunctionMetadataManager functionMetadataManager )
37
+ public WebFunctionsManager ( IOptionsMonitor < ScriptApplicationHostOptions > applicationHostOptions , ILoggerFactory loggerFactory , IHttpClientFactory httpClientFactory , ISecretManagerProvider secretManagerProvider , IFunctionsSyncManager functionsSyncManager , HostNameProvider hostNameProvider , IFunctionMetadataManager functionMetadataManager , IHostFunctionMetadataProvider hostFunctionMetadataProvider ,
38
+ IOptionsMonitor < LanguageWorkerOptions > languageWorkerOptions )
32
39
{
33
40
_applicationHostOptions = applicationHostOptions ;
34
41
_logger = loggerFactory ? . CreateLogger ( ScriptConstants . LogCategoryHostGeneral ) ;
@@ -37,6 +44,8 @@ public WebFunctionsManager(IOptionsMonitor<ScriptApplicationHostOptions> applica
37
44
_functionsSyncManager = functionsSyncManager ;
38
45
_hostNameProvider = hostNameProvider ;
39
46
_functionMetadataManager = functionMetadataManager ;
47
+ _hostFunctionMetadataProvider = hostFunctionMetadataProvider ;
48
+ _languageWorkerOptions = languageWorkerOptions ;
40
49
}
41
50
42
51
public async Task < IEnumerable < FunctionMetadataResponse > > GetFunctionsMetadata ( bool includeProxies )
@@ -144,12 +153,21 @@ await functionMetadata
144
153
await FileUtility . WriteAsync ( dataFilePath , functionMetadata . TestData ) ;
145
154
}
146
155
156
+ // Using HostFunctionMetadataProvider instead of IFunctionMetadataManager. More details logged here https://github.com/Azure/azure-functions-host/issues/10691
157
+ var metadata = ( await _hostFunctionMetadataProvider . GetFunctionMetadataAsync ( _languageWorkerOptions . CurrentValue . WorkerConfigs , true ) )
158
+ . FirstOrDefault ( metadata => Utility . FunctionNamesMatch ( metadata . Name , name ) ) ;
159
+
160
+ bool success = false ;
161
+ FunctionMetadataResponse functionMetadataResult = null ;
162
+ if ( metadata != null )
163
+ {
164
+ functionMetadataResult = await GetFunctionMetadataResponseAsync ( metadata , hostOptions , request ) ;
165
+ success = true ;
166
+ }
167
+
147
168
// we need to sync triggers if config changed, or the files changed
148
169
await _functionsSyncManager . TrySyncTriggersAsync ( ) ;
149
170
150
- // Setting force refresh to false as host restart causes a refersh already
151
- ( var success , var functionMetadataResult ) = await TryGetFunction ( name , request , false ) ;
152
-
153
171
return ( success , configChanged , functionMetadataResult ) ;
154
172
}
155
173
@@ -179,9 +197,8 @@ await functionMetadata
179
197
180
198
if ( functionMetadata != null )
181
199
{
182
- string routePrefix = await GetRoutePrefix ( hostOptions . RootScriptPath ) ;
183
- var baseUrl = $ "{ request . Scheme } ://{ request . Host } ";
184
- return ( true , await functionMetadata . ToFunctionMetadataResponse ( hostOptions , routePrefix , baseUrl ) ) ;
200
+ var functionMetadataResponse = await GetFunctionMetadataResponseAsync ( functionMetadata , hostOptions , request ) ;
201
+ return ( true , functionMetadataResponse ) ;
185
202
}
186
203
else
187
204
{
@@ -228,6 +245,13 @@ private void DeleteFunctionArtifacts(FunctionMetadataResponse function)
228
245
}
229
246
}
230
247
248
+ private static async Task < FunctionMetadataResponse > GetFunctionMetadataResponseAsync ( FunctionMetadata functionMetadata , ScriptJobHostOptions hostOptions , HttpRequest request )
249
+ {
250
+ string routePrefix = await GetRoutePrefix ( hostOptions . RootScriptPath ) ;
251
+ var baseUrl = $ "{ request . Scheme } ://{ request . Host } ";
252
+ return await functionMetadata . ToFunctionMetadataResponse ( hostOptions , routePrefix , baseUrl ) ;
253
+ }
254
+
231
255
// TODO : Due to lifetime scoping issues (this service lifetime is longer than the lifetime
232
256
// of HttpOptions sourced from host.json) we're reading the http route prefix anew each time
233
257
// to ensure we have the latest configured value.
0 commit comments