|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Globalization; |
3 | 4 | using System.Linq;
|
4 | 5 | using Azure.Functions.Cli.Kubernetes.KEDA.Models;
|
5 | 6 | using Azure.Functions.Cli.Kubernetes.KEDA.V2.Models;
|
@@ -47,31 +48,38 @@ public override IKubernetesResource GetKubernetesResource(string name, string @n
|
47 | 48 | };
|
48 | 49 | }
|
49 | 50 |
|
50 |
| - private static bool IsDurable(JToken trigger) => |
| 51 | + private static bool IsDurable(JToken trigger) => |
51 | 52 | trigger["type"].ToString().Equals("orchestrationTrigger", StringComparison.OrdinalIgnoreCase) ||
|
52 | 53 | trigger["type"].ToString().Equals("activityTrigger", StringComparison.OrdinalIgnoreCase) ||
|
53 | 54 | trigger["type"].ToString().Equals("entityTrigger", StringComparison.OrdinalIgnoreCase);
|
54 | 55 |
|
55 | 56 | private static IEnumerable<ScaledObjectTriggerV1Alpha1> GetDurableScalar(JObject hostJson)
|
56 | 57 | {
|
57 | 58 | // Reference: https://docs.microsoft.com/azure/azure-functions/durable/durable-functions-bindings#durable-functions-2-0-host-json
|
58 |
| - JObject storageProviderConfig = hostJson.SelectToken("extensions.durableTask.storageProvider") as JObject; |
59 |
| - string storageType = storageProviderConfig?["type"]?.ToString(); |
| 59 | + DurableTaskConfig durableTaskConfig = hostJson.SelectToken("extensions.durableTask")?.ToObject<DurableTaskConfig>(); |
| 60 | + string storageType = durableTaskConfig?.StorageProvider?["type"]?.ToString(); |
60 | 61 |
|
61 | 62 | // Custom storage types are supported starting in Durable Functions v2.4.2
|
62 | 63 | if (string.Equals(storageType, "MicrosoftSQL", StringComparison.OrdinalIgnoreCase) ||
|
63 | 64 | string.Equals(storageType, "mssql", StringComparison.OrdinalIgnoreCase))
|
64 | 65 | {
|
| 66 | + // By default, max 10 orchestrations and 1 activity per replica |
| 67 | + string query = string.Format( |
| 68 | + CultureInfo.InvariantCulture, |
| 69 | + "SELECT dt.GetScaleRecommendation({0}, {1})", |
| 70 | + durableTaskConfig.MaxConcurrentOrchestratorFunctions, |
| 71 | + durableTaskConfig.MaxConcurrentActivityFunctions); |
| 72 | + |
65 | 73 | yield return new ScaledObjectTriggerV1Alpha1
|
66 | 74 | {
|
67 | 75 | // MSSQL scaler reference: https://keda.sh/docs/2.2/scalers/mssql/
|
68 | 76 | Type = "mssql",
|
69 | 77 | Metadata = new Dictionary<string, string>
|
70 | 78 | {
|
71 | 79 | // Durable SQL scaling: https://microsoft.github.io/durabletask-mssql/#/scaling?id=worker-auto-scale
|
72 |
| - ["query"] = "SELECT dt.GetScaleRecommendation(10, 1)", // max 10 orchestrations and 1 activity per replica |
| 80 | + ["query"] = query, |
73 | 81 | ["targetValue"] = "1",
|
74 |
| - ["connectionStringFromEnv"] = storageProviderConfig?["connectionStringName"]?.ToString(), |
| 82 | + ["connectionStringFromEnv"] = durableTaskConfig.StorageProvider["connectionStringName"]?.ToString(), |
75 | 83 | }
|
76 | 84 | };
|
77 | 85 | }
|
|
0 commit comments