Finish an interrupted rebuild and replay the past without acting on it
The independent review found that a rebuild cut halfway was never finished (stops canceled or lowered), that old stop executions replayed from the broker queued a real sale, that a pending "close all" survived the restore, and that reconciliation and corporate actions touched accounts not rebuilt yet. The rebuild now keeps its starting point until it ends, protects the bot before the first row, meets the splits at their date and leaves the ledger alone until it is done. Dividends count the shares of after a split. A failed restore of a missing SQLite file leaves no empty database, and a failed migration can be tried again from the choice page. refs #69 #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24e20584d4
commit
5ef54b6f2a
17 files changed
+613
-80
No files matched your search
@@ -136,7 +136,53 @@ internal sealed partial class AnubisHost(
|
||||
/// For an error-page choice that writes into a missing SQLite file: the only place where a known installation gets a
|
||||
/// new one. Called while the choice holds <see cref="ExclusiveAsync"/>.
|
||||
/// </summary>
|
||||
internal Database OpenForChoice() => _db ??= Database.Open(Config.Db!, allowCreate: SqliteFileMissing);
|
||||
internal Database OpenForChoice()
|
||||
{
|
||||
if (_db is null)
|
||||
{
|
||||
_createdByChoice = SqliteFileMissing;
|
||||
_db = Database.Open(Config.Db!, allowCreate: _createdByChoice);
|
||||
}
|
||||
|
||||
return _db;
|
||||
}
|
||||
|
||||
private bool _createdByChoice;
|
||||
|
||||
/// <summary>
|
||||
/// A choice that failed or was cut halfway leaves nothing open that could create the missing file, and what it had
|
||||
/// begun to write steps aside: moved and not deleted, because in the meantime the true file may have come back.
|
||||
/// </summary>
|
||||
internal async Task AbandonChoiceAsync()
|
||||
{
|
||||
if (!_createdByChoice || _db is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _db.DisposeAsync().ConfigureAwait(false);
|
||||
_db = null;
|
||||
_createdByChoice = false;
|
||||
var path = Config.Db!.SqlitePath!;
|
||||
var aside = path + ".incompleto-" + clock.UtcNow.ToString("yyyyMMdd-HHmmss", System.Globalization.CultureInfo.InvariantCulture);
|
||||
foreach (var part in new[] { "", "-wal", "-shm" })
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path + part))
|
||||
{
|
||||
File.Move(path + part, aside + part, overwrite: true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
LogStepFailed(logger, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The choice is done: the database it opened is the one in use.</summary>
|
||||
internal void KeepChoice() => _createdByChoice = false;
|
||||
|
||||
/// <summary>Holds the loop still while an error-page choice works on the database.</summary>
|
||||
internal async Task<IDisposable> ExclusiveAsync(CancellationToken cancellationToken)
|
||||
|
||||
@@ -1168,6 +1168,7 @@ internal static partial class Forms
|
||||
}
|
||||
|
||||
var verdict = status.Identity.Verdict;
|
||||
var done = false;
|
||||
try
|
||||
{
|
||||
switch (choice)
|
||||
@@ -1197,19 +1198,31 @@ internal static partial class Forms
|
||||
break;
|
||||
case "usa-questo" when verdict is IdentityVerdict.DifferentInstallation or IdentityVerdict.StaleDatabase or IdentityVerdict.MissingFile:
|
||||
// An old copy may have an old schema: it is brought up to date, after its own backup, before it is protected.
|
||||
// Asked by the user: one more attempt, even after one that failed.
|
||||
host.MigrationFailed = null;
|
||||
await host.MigrateAsync(new Backups(config.Data, clock), ct).ConfigureAwait(false);
|
||||
await Installation.RenewAsync(host.OpenForChoice(), config.Data, clock, "Database scelto dalla pagina d'errore", ct).ConfigureAwait(false);
|
||||
break;
|
||||
default:
|
||||
return Results.Redirect("/?errore=scelta");
|
||||
}
|
||||
|
||||
done = true;
|
||||
}
|
||||
catch (Exception ex) when (IsArchiveProblem(ex))
|
||||
{
|
||||
LogChoiceFailed(logger, ex, choice);
|
||||
return Results.Redirect("/?errore=importazione");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!done)
|
||||
{
|
||||
await host.AbandonChoiceAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
host.KeepChoice();
|
||||
LogChoice(logger, choice);
|
||||
|
||||
// Reset while the loop is still held: released first, it could start the application again before the reset
|
||||
|
||||
Reference in new issue
Block a user