|
3 | 3 | using KustoSchemaTools.Model; |
4 | 4 | using KustoSchemaTools.Parser; |
5 | 5 | using Microsoft.Extensions.Logging; |
| 6 | +using System.Collections.Concurrent; |
| 7 | +using System.Data; |
6 | 8 | using System.Text; |
7 | 9 |
|
8 | 10 | namespace KustoSchemaTools |
@@ -87,21 +89,32 @@ public async Task Import(string path, string databaseName, bool includeColumns) |
87 | 89 | } |
88 | 90 |
|
89 | 91 |
|
90 | | - public async Task Apply(string path, string databaseName) |
| 92 | + public async Task<ConcurrentDictionary<string,Exception>> Apply(string path, string databaseName) |
91 | 93 | { |
92 | 94 | var clustersFile = File.ReadAllText(Path.Combine(path, "clusters.yml")); |
93 | 95 | var clusters = Serialization.YamlPascalCaseDeserializer.Deserialize<Clusters>(clustersFile); |
94 | 96 |
|
95 | 97 | var yamlHandler = YamlDatabaseHandlerFactory.Create(path, databaseName); |
96 | 98 | var yamlDb = await yamlHandler.LoadAsync(); |
97 | 99 |
|
98 | | - foreach (var cluster in clusters.Connections) |
| 100 | + var results = new ConcurrentDictionary<string,Exception>(); |
| 101 | + |
| 102 | + await Parallel.ForEachAsync(clusters.Connections, new ParallelOptions { MaxDegreeOfParallelism = 1}, async (cluster, token) => |
99 | 103 | { |
100 | | - Log.LogInformation($"Generating diff markdown for {Path.Combine(path, databaseName)} => {cluster}/{databaseName}"); |
| 104 | + try |
| 105 | + { |
| 106 | + Log.LogInformation($"Generating and applying script for {Path.Combine(path, databaseName)} => {cluster}/{databaseName}"); |
| 107 | + var dbHandler = KustoDatabaseHandlerFactory.Create(cluster.Url, databaseName); |
| 108 | + await dbHandler.WriteAsync(yamlDb); |
| 109 | + results.TryAdd(cluster.Url, null); |
| 110 | + } |
| 111 | + catch (Exception ex) |
| 112 | + { |
| 113 | + results.TryAdd(cluster.Url, ex); |
| 114 | + } |
| 115 | + }); |
101 | 116 |
|
102 | | - var dbHandler = KustoDatabaseHandlerFactory.Create(cluster.Url, databaseName); |
103 | | - await dbHandler.WriteAsync(yamlDb); |
104 | | - } |
| 117 | + return results; |
105 | 118 | } |
106 | 119 | } |
107 | 120 | } |
0 commit comments