Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}