Skip to content

Commit

Permalink
Merge pull request #77 from github/caol-ila-parallel-rollouts
Browse files Browse the repository at this point in the history
Add parallel rollouts
  • Loading branch information
caol-ila authored Aug 2, 2024
2 parents 2b2b886 + bb53913 commit 9a1851f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions KustoSchemaTools/KustoSchemaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,21 +89,32 @@ public async Task Import(string path, string databaseName, bool includeColumns)
}


public async Task Apply(string path, string databaseName)
public async Task<ConcurrentDictionary<string,Exception>> Apply(string path, string databaseName)
{
var clustersFile = File.ReadAllText(Path.Combine(path, "clusters.yml"));
var clusters = Serialization.YamlPascalCaseDeserializer.Deserialize<Clusters>(clustersFile);

var yamlHandler = YamlDatabaseHandlerFactory.Create(path, databaseName);
var yamlDb = await yamlHandler.LoadAsync();

foreach (var cluster in clusters.Connections)
var results = new ConcurrentDictionary<string,Exception>();

await Parallel.ForEachAsync(clusters.Connections, 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;
}
}
}

0 comments on commit 9a1851f

Please sign in to comment.