Skip to content

Commit edbfc8e

Browse files
committed
Enable SyncTriggers cache; Support Disable Config
1 parent fa14eec commit edbfc8e

File tree

6 files changed

+46
-31
lines changed

6 files changed

+46
-31
lines changed

src/WebJobs.Script.WebHost/Extensions/FunctionMetadataExtensions.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,21 @@ public static async Task<FunctionMetadataResponse> ToFunctionMetadataResponse(th
6969
/// <returns>JObject that represent the trigger for scale controller to consume</returns>
7070
public static async Task<JObject> ToFunctionTrigger(this FunctionMetadata functionMetadata, ScriptHostConfiguration config)
7171
{
72-
// Only look at the function if it's not disabled
73-
if (!functionMetadata.IsDisabled)
74-
{
75-
// Get function.json path
76-
var functionPath = Path.Combine(config.RootScriptPath, functionMetadata.Name);
77-
var functionMetadataFilePath = Path.Combine(functionPath, ScriptConstants.FunctionMetadataFileName);
72+
// Get function.json path
73+
var functionPath = Path.Combine(config.RootScriptPath, functionMetadata.Name);
74+
var functionMetadataFilePath = Path.Combine(functionPath, ScriptConstants.FunctionMetadataFileName);
7875

79-
// Read function.json as a JObject
80-
var functionConfig = await GetFunctionConfig(functionMetadataFilePath);
76+
// Read function.json as a JObject
77+
var functionConfig = await GetFunctionConfig(functionMetadataFilePath);
8178

82-
// Find the trigger and add functionName to it
83-
foreach (JObject binding in (JArray)functionConfig["bindings"])
79+
// Find the trigger and add functionName to it
80+
foreach (JObject binding in (JArray)functionConfig["bindings"])
81+
{
82+
var type = (string)binding["type"];
83+
if (type.EndsWith("Trigger", StringComparison.OrdinalIgnoreCase))
8484
{
85-
var type = (string)binding["type"];
86-
if (type.EndsWith("Trigger", StringComparison.OrdinalIgnoreCase))
87-
{
88-
binding.Add("functionName", functionMetadata.Name);
89-
return binding;
90-
}
85+
binding.Add("functionName", functionMetadata.Name);
86+
return binding;
9187
}
9288
}
9389

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ namespace Microsoft.Azure.WebJobs.Script.WebHost.Management
2525
{
2626
public sealed class FunctionsSyncManager : IFunctionsSyncManager, IDisposable
2727
{
28-
// Until ANT 82 is fully released, the default value is disabled and we continue
29-
// to return just the trigger data.
30-
// After ANT 82, we will change the default to enabled.
31-
// Note that this app setting is honored by both GeoMaster and Runtime.
32-
public const string AzureWebsiteArmCacheEnabledDefaultValue = "0";
33-
3428
private const string HubName = "HubName";
3529
private const string TaskHubName = "taskHubName";
3630
private const string Connection = "connection";
@@ -66,7 +60,7 @@ internal bool ArmCacheEnabled
6660
{
6761
get
6862
{
69-
return _settings.GetSettingOrDefault(EnvironmentSettingNames.AzureWebsiteArmCacheEnabled, AzureWebsiteArmCacheEnabledDefaultValue) == "1";
63+
return _settings.GetSettingOrDefault(EnvironmentSettingNames.AzureWebsiteArmCacheEnabled, "1") == "1";
7064
}
7165
}
7266

src/WebJobs.Script/Config/ScriptSettingsManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,18 @@ public virtual void SetSetting(string settingKey, string settingValue)
9999

100100
Environment.SetEnvironmentVariable(settingKey, settingValue);
101101
}
102+
103+
public bool SettingIsEnabled(string settingKey)
104+
{
105+
string value = GetSetting(settingKey);
106+
if (!string.IsNullOrEmpty(value) &&
107+
(string.Compare(value, "1", StringComparison.OrdinalIgnoreCase) == 0 ||
108+
string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0))
109+
{
110+
return true;
111+
}
112+
113+
return false;
114+
}
102115
}
103116
}

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,10 @@ private static FunctionMetadata ParseFunctionMetadata(string functionName, JObje
10531053
}
10541054
}
10551055

1056-
// A function can be disabled at the trigger or function level
1057-
if (IsDisabled(triggerDisabledValue, settingsManager) ||
1056+
// A function can be disabled at the trigger or function level, or via an
1057+
// app level per function setting
1058+
if (settingsManager.SettingIsEnabled($"AzureWebJobs.{functionName}.Disabled") ||
1059+
IsDisabled(triggerDisabledValue, settingsManager) ||
10581060
IsDisabled((JValue)configMetadata["disabled"], settingsManager))
10591061
{
10601062
functionMetadata.IsDisabled = true;
@@ -1980,10 +1982,7 @@ private static bool IsDisabled(JToken isDisabledValue, ScriptSettingsManager set
19801982
else
19811983
{
19821984
string settingName = (string)isDisabledValue;
1983-
string value = settingsManager.GetSetting(settingName);
1984-
if (!string.IsNullOrEmpty(value) &&
1985-
(string.Compare(value, "1", StringComparison.OrdinalIgnoreCase) == 0 ||
1986-
string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0))
1985+
if (settingsManager.SettingIsEnabled(settingName))
19871986
{
19881987
return true;
19891988
}

test/WebJobs.Script.Tests/Management/FunctionsSyncManagerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public async Task TrySyncTriggers_ConfigurationNotReady_ReturnsFalse()
188188
public void ArmCacheEnabled_VerifyDefault()
189189
{
190190
_scriptSettingsManagerMock.Setup(p => p.GetSetting(EnvironmentSettingNames.AzureWebsiteArmCacheEnabled)).Returns((string)null);
191-
Assert.False(_functionsSyncManager.ArmCacheEnabled);
191+
Assert.True(_functionsSyncManager.ArmCacheEnabled);
192192
}
193193

194194
[Theory]

test/WebJobs.Script.Tests/ScriptHostTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public void ReadFunctionMetadata_Succeeds()
6666
var functionDirectories = Directory.EnumerateDirectories(config.RootScriptPath);
6767
var metadata = ScriptHost.ReadFunctionMetadata(functionDirectories, traceWriter, null, functionErrors, functionWhitelist: config.Functions);
6868
Assert.Equal(51, metadata.Count);
69+
70+
var disabledFunctions = metadata.Where(p => p.IsDisabled).OrderBy(p => p.Name).ToArray();
71+
Assert.Equal(2, disabledFunctions.Length);
72+
Assert.Equal("HttpTrigger-Disabled", disabledFunctions[0].Name);
73+
Assert.Equal("SendGrid", disabledFunctions[1].Name);
6974
}
7075

7176
[Fact]
@@ -1753,10 +1758,13 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit)
17531758
}
17541759
}
17551760

1756-
public class TestFixture
1761+
public class TestFixture : IDisposable
17571762
{
17581763
public TestFixture()
17591764
{
1765+
// disable function using app level setting - test verifies this above
1766+
Environment.SetEnvironmentVariable("AzureWebJobs.SendGrid.Disabled", "1");
1767+
17601768
ScriptHostConfiguration config = new ScriptHostConfiguration()
17611769
{
17621770
TraceWriter = NullTraceWriter.Instance
@@ -1769,6 +1777,11 @@ public TestFixture()
17691777
}
17701778

17711779
public ScriptHost Host { get; private set; }
1780+
1781+
public void Dispose()
1782+
{
1783+
Environment.SetEnvironmentVariable("AzureWebJobs.SendGrid.Disabled", null);
1784+
}
17721785
}
17731786
}
17741787
}

0 commit comments

Comments
 (0)