Skip to content

Commit 8a2368f

Browse files
authored
[pack] Making bundles default, optimizing start up code path (#5254)
1 parent c1e62db commit 8a2368f

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"version": "2.0"
2+
"version": "2.0",
3+
"extensionBundle": {
4+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5+
"version": "[1.*, 2.0.0)"
6+
}
37
}

src/WebJobs.Script/Config/HostJsonFileConfigurationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ internal JObject LoadHostConfig(string configFilePath)
204204

205205
private JObject GetDefaultHostConfigObject()
206206
{
207-
var hostJsonJObj = JObject.Parse("{'version': '2.0'}");
207+
var hostJsonJObj = JObject.Parse("{'version': '2.0', 'extensionBundle': { 'id': 'Microsoft.Azure.Functions.ExtensionBundle', 'version': '[1.*, 2.0.0)'}}");
208208
if (string.Equals(_configurationSource.Environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName), "powershell", StringComparison.InvariantCultureIgnoreCase)
209209
&& !_configurationSource.Environment.IsFileSystemReadOnly())
210210
{

src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,23 @@ public Type[] GetStartupTypes()
6262
public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()
6363
{
6464
string binPath;
65-
if (_extensionBundleManager.IsExtensionBundleConfigured())
65+
var functionMetadataCollection = _functionMetadataProvider.GetFunctionMetadata(forceRefresh: true);
66+
HashSet<string> bindingsSet = null;
67+
var bundleConfigured = _extensionBundleManager.IsExtensionBundleConfigured();
68+
69+
if (bundleConfigured)
6670
{
71+
bindingsSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
72+
73+
// Generate a Hashset of all the binding types used in the function app
74+
foreach (var functionMetadata in functionMetadataCollection)
75+
{
76+
foreach (var binding in functionMetadata.Bindings)
77+
{
78+
bindingsSet.Add(binding.Type);
79+
}
80+
}
81+
6782
string extensionBundlePath = await _extensionBundleManager.GetExtensionBundlePath();
6883
if (string.IsNullOrEmpty(extensionBundlePath))
6984
{
@@ -85,14 +100,11 @@ public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()
85100

86101
var startupTypes = new List<Type>();
87102

88-
var functionBindings = _functionMetadataProvider.GetFunctionMetadata(forceRefresh: true).SelectMany(f => f.Bindings.Select(b => b.Type));
89-
90-
var bundleConfigured = _extensionBundleManager.IsExtensionBundleConfigured();
91103
foreach (var extensionItem in extensionItems)
92104
{
93105
if (!bundleConfigured
94106
|| extensionItem.Bindings.Count == 0
95-
|| extensionItem.Bindings.Intersect(functionBindings, StringComparer.OrdinalIgnoreCase).Any())
107+
|| extensionItem.Bindings.Intersect(bindingsSet, StringComparer.OrdinalIgnoreCase).Any())
96108
{
97109
string startupExtensionName = extensionItem.Name ?? extensionItem.TypeName;
98110
_logger.ScriptStartUpLoadingStartUpExtension(startupExtensionName);

test/WebJobs.Script.Tests/Configuration/HostJsonFileConfigurationSourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.Configuration
1818
{
1919
public class HostJsonFileConfigurationSourceTests
2020
{
21-
private readonly string _defaultHostJson = "{\r\n \"version\": \"2.0\"\r\n}";
21+
private readonly string _defaultHostJson = "{\r\n \"version\": \"2.0\",\r\n \"extensionBundle\": {\r\n \"id\": \"Microsoft.Azure.Functions.ExtensionBundle\",\r\n \"version\": \"[1.*, 2.0.0)\"\r\n }\r\n}";
2222
private readonly ScriptApplicationHostOptions _options;
2323
private readonly string _hostJsonFile;
2424
private readonly TestLoggerProvider _loggerProvider = new TestLoggerProvider();

0 commit comments

Comments
 (0)