Skip to content

Commit 056d5d4

Browse files
committed
Fixing DurableTask SyncTriggers config parsing
1 parent cac3cb2 commit 056d5d4

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,19 @@ private async Task<Dictionary<string, string>> ReadDurableTaskConfig()
358358
var config = new Dictionary<string, string>();
359359
if (FileUtility.FileExists(hostJsonPath))
360360
{
361-
var hostJson = JObject.Parse(await FileUtility.ReadAsync(hostJsonPath));
362-
JToken durableTaskValue;
361+
var json = JObject.Parse(await FileUtility.ReadAsync(hostJsonPath));
362+
363+
// get the DurableTask extension config section
364+
JToken extensionsValue;
365+
if (json.TryGetValue("extensions", StringComparison.OrdinalIgnoreCase, out extensionsValue) && extensionsValue != null)
366+
{
367+
json = (JObject)extensionsValue;
368+
}
363369

364370
// we will allow case insensitivity given it is likely user hand edited
365371
// see https://github.com/Azure/azure-functions-durable-extension/issues/111
366-
//
367-
// We're looking for {VALUE}
368-
// {
369-
// "durableTask": {
370-
// "hubName": "{VALUE}",
371-
// "azureStorageConnectionStringName": "{VALUE}"
372-
// }
373-
// }
374-
if (hostJson.TryGetValue(DurableTask, StringComparison.OrdinalIgnoreCase, out durableTaskValue) && durableTaskValue != null)
372+
JToken durableTaskValue;
373+
if (json.TryGetValue(DurableTask, StringComparison.OrdinalIgnoreCase, out durableTaskValue) && durableTaskValue != null)
375374
{
376375
try
377376
{

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,20 @@ private static IFileSystem CreateFileSystem(ScriptApplicationHostOptions hostOpt
384384
fileSystem.SetupGet(f => f.File).Returns(fileBase.Object);
385385
fileBase.Setup(f => f.Exists(Path.Combine(rootPath, "host.json"))).Returns(true);
386386

387-
hostJsonContent = hostJsonContent ?? @"{ ""durableTask"": { ""HubName"": ""TestHubValue"", ""azureStorageConnectionStringName"": ""DurableStorage"" }}";
387+
var durableConfig = new JObject
388+
{
389+
{ "HubName", "TestHubValue" },
390+
{ "azureStorageConnectionStringName", "DurableStorage" }
391+
};
392+
var extensionsConfig = new JObject
393+
{
394+
{ "durableTask", durableConfig }
395+
};
396+
var defaultHostConfig = new JObject
397+
{
398+
{ "extensions", extensionsConfig }
399+
};
400+
hostJsonContent = hostJsonContent ?? defaultHostConfig.ToString();
388401
var testHostJsonStream = new MemoryStream(Encoding.UTF8.GetBytes(hostJsonContent));
389402
testHostJsonStream.Position = 0;
390403
fileBase.Setup(f => f.Open(Path.Combine(rootPath, @"host.json"), It.IsAny<FileMode>(), It.IsAny<FileAccess>(), It.IsAny<FileShare>())).Returns(testHostJsonStream);

0 commit comments

Comments
 (0)