Merge branch 'fase9-fix-conti' into fase-9

This commit is contained in:
Alby96 committed 2026-12-01 22:28:59 +01:00
commit e58a26e8fa
20 files changed
+814 -174

No files matched your search

+23 -1
View File
@@ -62,6 +62,7 @@ internal sealed partial class AnubisHost(
private readonly AccessGuards _accessGuards = new(clock);
private readonly TimeSpan _interval = overrides?.DatabaseCheckInterval ?? TimeSpan.FromSeconds(5);
private readonly TimeSpan _tradingRetry = overrides?.TradingRetry ?? TimeSpan.FromMinutes(1);
private readonly Lock _gate = new();
// One step of the loop or one error-page choice at a time: a restore must not race the start that would follow it.
@@ -712,7 +713,11 @@ internal sealed partial class AnubisHost(
{
try
{
await trading.StartAsync(cancellationToken).ConfigureAwait(false);
while (!await TryStartAsync(trading, cancellationToken).ConfigureAwait(false))
{
await Task.Delay(_tradingRetry, cancellationToken).ConfigureAwait(false);
}
await trading.RunAsync(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
@@ -724,6 +729,20 @@ internal sealed partial class AnubisHost(
}
}
private async Task<bool> TryStartAsync(TradingService trading, CancellationToken cancellationToken)
{
try
{
await trading.StartAsync(cancellationToken).ConfigureAwait(false);
return true;
}
catch (Exception ex) when (ex is not OperationCanceledException || !cancellationToken.IsCancellationRequested)
{
LogTradingStartFailed(logger, ex, _tradingRetry);
return false;
}
}
// The jobs table keeps the outcome of the last run of each job (Diario e sistema, SPEC 13.6).
private async Task RecordJobsAsync(EventSubscription<JobRun> runs, CancellationToken cancellationToken)
{
@@ -859,6 +878,9 @@ internal sealed partial class AnubisHost(
[LoggerMessage(Level = LogLevel.Error, Message = "Trading stopped")]
private static partial void LogTradingFailed(ILogger logger, Exception exception);
[LoggerMessage(Level = LogLevel.Error, Message = "Trading could not start: tried again in {Delay}")]
private static partial void LogTradingStartFailed(ILogger logger, Exception exception, TimeSpan delay);
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not record the run of job {Job}")]
private static partial void LogJobRecordFailed(ILogger logger, Exception exception, string job);
}