From 0924eb55565231ef072a29fdb2ae7c19267926a7 Mon Sep 17 00:00:00 2001 From: Thomas Mahlberg Date: Thu, 1 Aug 2024 16:55:04 +0200 Subject: [PATCH 1/2] Add parallel rollouts --- KustoSchemaTools/KustoSchemaHandler.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/KustoSchemaTools/KustoSchemaHandler.cs b/KustoSchemaTools/KustoSchemaHandler.cs index e7bf16f..5cf01a2 100644 --- a/KustoSchemaTools/KustoSchemaHandler.cs +++ b/KustoSchemaTools/KustoSchemaHandler.cs @@ -3,6 +3,8 @@ using KustoSchemaTools.Model; using KustoSchemaTools.Parser; using Microsoft.Extensions.Logging; +using System.Collections.Concurrent; +using System.Data; using System.Text; namespace KustoSchemaTools @@ -87,7 +89,7 @@ public async Task Import(string path, string databaseName, bool includeColumns) } - public async Task Apply(string path, string databaseName) + public async Task> Apply(string path, string databaseName) { var clustersFile = File.ReadAllText(Path.Combine(path, "clusters.yml")); var clusters = Serialization.YamlPascalCaseDeserializer.Deserialize(clustersFile); @@ -95,13 +97,24 @@ public async Task Apply(string path, string databaseName) var yamlHandler = YamlDatabaseHandlerFactory.Create(path, databaseName); var yamlDb = await yamlHandler.LoadAsync(); - foreach (var cluster in clusters.Connections) + var results = new ConcurrentDictionary(); + + await Parallel.ForEachAsync(clusters.Connections, new ParallelOptions { MaxDegreeOfParallelism = 1}, async (cluster, token) => { - Log.LogInformation($"Generating diff markdown for {Path.Combine(path, databaseName)} => {cluster}/{databaseName}"); + try + { + Log.LogInformation($"Generating and applying script for {Path.Combine(path, databaseName)} => {cluster}/{databaseName}"); + var dbHandler = KustoDatabaseHandlerFactory.Create(cluster.Url, databaseName); + await dbHandler.WriteAsync(yamlDb); + results.TryAdd(cluster.Url, null); + } + catch (Exception ex) + { + results.TryAdd(cluster.Url, ex); + } + }); - var dbHandler = KustoDatabaseHandlerFactory.Create(cluster.Url, databaseName); - await dbHandler.WriteAsync(yamlDb); - } + return results; } } } From bb53913170a440ab1867edb62c66b6e8e79e4636 Mon Sep 17 00:00:00 2001 From: Thomas Mahlberg Date: Thu, 1 Aug 2024 16:55:18 +0200 Subject: [PATCH 2/2] Add parallel rollouts --- KustoSchemaTools/KustoSchemaHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KustoSchemaTools/KustoSchemaHandler.cs b/KustoSchemaTools/KustoSchemaHandler.cs index 5cf01a2..9742080 100644 --- a/KustoSchemaTools/KustoSchemaHandler.cs +++ b/KustoSchemaTools/KustoSchemaHandler.cs @@ -99,7 +99,7 @@ public async Task> Apply(string path, str var results = new ConcurrentDictionary(); - await Parallel.ForEachAsync(clusters.Connections, new ParallelOptions { MaxDegreeOfParallelism = 1}, async (cluster, token) => + await Parallel.ForEachAsync(clusters.Connections, async (cluster, token) => { try {