Skip to content

Commit

Permalink
Replacing the cached value of workerRuntime (#9072)
Browse files Browse the repository at this point in the history
  • Loading branch information
soninaren authored and VpOfEngineering committed Feb 6, 2023
1 parent 2fbc62d commit 5611f0a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/WebJobs.Script/Host/FunctionMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<ImmutableArray<FunctionMetadata>> GetFunctionMetadataAsync(IEn

_logger.LogInformation("Worker indexing is enabled");

FunctionMetadataResult functionMetadataResult = await _workerFunctionMetadataProvider?.GetFunctionMetadataAsync(workerConfigs, SystemEnvironment.Instance, forceRefresh);
FunctionMetadataResult functionMetadataResult = await _workerFunctionMetadataProvider?.GetFunctionMetadataAsync(workerConfigs, forceRefresh);
FunctionErrors = _workerFunctionMetadataProvider.FunctionErrors;

if (functionMetadataResult.UseDefaultMetadataIndexing)
Expand Down
2 changes: 1 addition & 1 deletion src/WebJobs.Script/Host/IWorkerFunctionMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ internal interface IWorkerFunctionMetadataProvider
/// Attempts to get function metadata from Out-of-Proc language workers
/// </summary>
/// <returns>FunctionMetadataResult that either contains the function metadata or indicates that a fall back option for fetching metadata should be used</returns>
Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh = false);
Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, bool forceRefresh = false);
}
}
10 changes: 7 additions & 3 deletions src/WebJobs.Script/Host/WorkerFunctionMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class WorkerFunctionMetadataProvider : IWorkerFunctionMetadataProvider
private readonly ILogger _logger;
private readonly IEnvironment _environment;
private readonly IWebHostRpcWorkerChannelManager _channelManager;
private readonly string _workerRuntime;
private string _workerRuntime;
private ImmutableArray<FunctionMetadata> _functions;

public WorkerFunctionMetadataProvider(
Expand All @@ -43,8 +43,12 @@ public WorkerFunctionMetadataProvider(
public ImmutableDictionary<string, ImmutableArray<string>> FunctionErrors
=> _functionErrors.ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.ToImmutableArray());

public async Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh)
public async Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, bool forceRefresh)
{
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);

_logger.LogInformation("Fetching metadata for workerRuntime: {workerRuntime}", _workerRuntime);

IEnumerable<FunctionMetadata> functions = new List<FunctionMetadata>();
_logger.FunctionMetadataProviderParsingFunctions();

Expand Down Expand Up @@ -91,7 +95,7 @@ public async Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<R
_logger.FunctionMetadataProviderFunctionFound(_functions.IsDefault ? 0 : _functions.Count());

// Validate if the app has functions in legacy format and add in logs to inform about the mixed app
_ = Task.Delay(TimeSpan.FromMinutes(1)).ContinueWith(t => ValidateFunctionAppFormat(_scriptApplicationHostOptions.Value.ScriptPath, _logger, environment));
_ = Task.Delay(TimeSpan.FromMinutes(1)).ContinueWith(t => ValidateFunctionAppFormat(_scriptApplicationHostOptions.Value.ScriptPath, _logger, _environment));

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static IServiceCollection AddFunctionMetadataManager(this IServiceCollec
var metadataProvider = new HostFunctionMetadataProvider(optionsMonitor, NullLogger<HostFunctionMetadataProvider>.Instance, metricsLogger);

var workerProvider = new Mock<IWorkerFunctionMetadataProvider>();
workerProvider.Setup(m => m.GetFunctionMetadataAsync(It.IsAny<IEnumerable<RpcWorkerConfig>>(), SystemEnvironment.Instance, false)).Returns(Task.FromResult(new FunctionMetadataResult(true, ImmutableArray<FunctionMetadata>.Empty)));
workerProvider.Setup(m => m.GetFunctionMetadataAsync(It.IsAny<IEnumerable<RpcWorkerConfig>>(), false)).Returns(Task.FromResult(new FunctionMetadataResult(true, ImmutableArray<FunctionMetadata>.Empty)));
var defaultProvider = new FunctionMetadataProvider(NullLogger<FunctionMetadataProvider>.Instance, workerProvider.Object, metadataProvider);
var metadataManager = TestFunctionMetadataManager.GetFunctionMetadataManager(new OptionsWrapper<ScriptJobHostOptions>(new ScriptJobHostOptions()), defaultProvider, new List<IFunctionProvider>(), new OptionsWrapper<HttpWorkerOptions>(new HttpWorkerOptions()), new NullLoggerFactory(), new TestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions()));
services.AddSingleton<IFunctionMetadataManager>(metadataManager);
Expand Down
2 changes: 1 addition & 1 deletion test/WebJobs.Script.Tests/FunctionMetadataProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void GetFunctionMetadataAsync_WorkerIndexing_HostFallback()
var defaultProvider = new FunctionMetadataProvider(_logger, _workerFunctionMetadataProvider.Object, _hostFunctionMetadataProvider.Object);

FunctionMetadataResult result = new FunctionMetadataResult(true, functionMetadataCollection.ToImmutableArray());
_workerFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, environment, false)).Returns(Task.FromResult(result));
_workerFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, false)).Returns(Task.FromResult(result));
_hostFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, environment, false)).Returns(Task.FromResult(functionMetadataCollection.ToImmutableArray()));

// Act
Expand Down

0 comments on commit 5611f0a

Please sign in to comment.