Drain Eve commands through provider state
This commit is contained in:
parent
b867e688e2
commit
6b435b8f13
14 changed files with 613 additions and 33 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Aetheria.State;
|
||||
using Aetheria.State.Documents;
|
||||
|
||||
var root = args.Length > 0 && !args[0].StartsWith("--", StringComparison.Ordinal)
|
||||
? Path.GetFullPath(args[0])
|
||||
|
|
@ -10,14 +11,72 @@ var statePath = string.IsNullOrWhiteSpace(explicitStatePath)
|
|||
? AetheriaStatePaths.ResolveDefaultStatePath(root)
|
||||
: Path.GetFullPath(explicitStatePath);
|
||||
var deleteApplied = !args.Any(arg => string.Equals(arg, "--keep", StringComparison.OrdinalIgnoreCase));
|
||||
var runtimeId = "aetheria-state-apply-pending";
|
||||
var runtimePendingBefore = CountPendingRuntimeCommits(statePath);
|
||||
var evePendingBefore = CountPendingEveCommands(statePath);
|
||||
var now = DateTimeOffset.UtcNow.ToString("O");
|
||||
|
||||
await using var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-state-apply-pending");
|
||||
await using var node = await AetheriaStateNode.OpenAsync(statePath, runtimeId);
|
||||
var report = await AetheriaRuntimeCommitLogApplier.ApplyPendingAsync(node, deleteApplied);
|
||||
var eveReport = await AetheriaEveCommandBridge.ApplyPendingAsync(node, deleteApplied);
|
||||
var commitStatus = new AetheriaRuntimeCommitDrainStatus
|
||||
{
|
||||
RuntimeId = runtimeId,
|
||||
StatePath = statePath,
|
||||
LastPollAtUtc = now,
|
||||
LastAppliedAtUtc = report.AppliedPaths.Length > 0 ? now : "",
|
||||
PendingBeforeApply = runtimePendingBefore,
|
||||
CommandsApplied = report.AppliedPaths.Length,
|
||||
AppliedPlayerSettings = report.AppliedPlayerSettings,
|
||||
AppliedLoadoutTemplates = report.AppliedLoadoutTemplates,
|
||||
AppliedRunCheckpoints = report.AppliedRunCheckpoints,
|
||||
Status = "ok"
|
||||
};
|
||||
var eveStatus = new AetheriaEveCommandDrainStatus
|
||||
{
|
||||
RuntimeId = runtimeId,
|
||||
StatePath = statePath,
|
||||
LastPollAtUtc = now,
|
||||
LastAcceptedAtUtc = eveReport.AcceptedPaths.Length > 0 ? now : "",
|
||||
PendingBeforeApply = evePendingBefore,
|
||||
CommandsAccepted = eveReport.AcceptedPaths.Length,
|
||||
CommandsRejected = eveReport.RejectedCommands,
|
||||
AppliedCatalogRefreshes = eveReport.AppliedCatalogRefreshes,
|
||||
AppliedOperationsRefreshes = eveReport.AppliedOperationsRefreshes,
|
||||
LastRejectedCommand = eveReport.LastRejectedCommand,
|
||||
LastRejectedReason = eveReport.LastRejectedReason,
|
||||
Status = eveReport.RejectedCommands > 0 ? "rejected" : "ok"
|
||||
};
|
||||
await node.PutRuntimeCommitDrainStatusAsync(commitStatus);
|
||||
await node.PutEveCommandDrainStatusAsync(eveStatus);
|
||||
await node.PutOperationsSurfaceAsync(AetheriaOperationsSurfaceProjector.Build(commitStatus, eveStatus));
|
||||
await node.PutProviderAdvertisementAsync(AetheriaProviderAdvertisementProjector.Build(statePath, now));
|
||||
await node.FlushAsync();
|
||||
|
||||
Console.WriteLine($"Applied pending Aetheria runtime commits: {statePath}");
|
||||
Console.WriteLine($"Player settings: {report.AppliedPlayerSettings}");
|
||||
Console.WriteLine($"Loadout templates: {report.AppliedLoadoutTemplates}");
|
||||
Console.WriteLine($"Run checkpoints: {report.AppliedRunCheckpoints}");
|
||||
Console.WriteLine($"Commands applied: {report.AppliedPaths.Length}");
|
||||
Console.WriteLine($"Eve commands accepted: {eveReport.AcceptedPaths.Length}");
|
||||
Console.WriteLine($"Eve commands rejected: {eveReport.RejectedCommands}");
|
||||
Console.WriteLine($"Eve catalog refreshes: {eveReport.AppliedCatalogRefreshes}");
|
||||
Console.WriteLine($"Eve operations refreshes: {eveReport.AppliedOperationsRefreshes}");
|
||||
if (!deleteApplied)
|
||||
Console.WriteLine("Applied command files were kept because --keep was supplied.");
|
||||
|
||||
static int CountPendingRuntimeCommits(string statePath)
|
||||
{
|
||||
var pendingDirectory = statePath + ".pending";
|
||||
return Directory.Exists(pendingDirectory)
|
||||
? Directory.EnumerateFiles(pendingDirectory, "*.cc").Count()
|
||||
: 0;
|
||||
}
|
||||
|
||||
static int CountPendingEveCommands(string statePath)
|
||||
{
|
||||
var pendingDirectory = AetheriaEveCommandBridge.GetPendingDirectory(statePath);
|
||||
return Directory.Exists(pendingDirectory)
|
||||
? Directory.EnumerateFiles(pendingDirectory, "*.cc").Count()
|
||||
: 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue