fix: logging never fails a job, one backup retention, first copy after the upgrade

Owner review 2, phase 2 review findings (scheduler core).

- Log.Write caught only IOException. Microsoft.Extensions.Logging wraps
  provider failures in an AggregateException, so a log line that could not
  be written (in tests: the process-wide sink of a stopped server whose log
  folder was gone) escaped JobEngine.RunAsync's catch before the failure was
  stored: the job stayed running and the worker faulted. This was the cause
  of the intermittent JobApiTests/ArchiveModuleTests failures. Log.Write now
  drops any non-fatal sink failure, TeeLogSink keeps a line from the other
  sinks, FileLogSink drops a line it cannot write and reopens the file at the
  next one, and LoggerSink drops what the providers throw. The scheduler's
  loop relies on the same guarantee.
- The daily backup loop (RunDailyAsync, IsDue, Interval, CheckInterval) had
  no caller since the index-backup schedule replaced it; it is removed and
  the DatabaseBackups summary describes the schedule.
- The first copy after the upgrade no longer waits a day (or for 03:00):
  SystemSchedule.LastDone seeds a new row due at once when its work was last
  done a period or more before, and both hosts pass the newest copy in the
  backups folder for index-backup.
- Back up now (Settings and Archive), the copy kept before a restore and a
  backup job that keeps fewer prune to the largest Copies kept of the backup
  schedules (DatabaseBackups.KeptAsync), not a fixed three. The four
  tooltips that promised three daily copies are reworded (en, it) and their
  stale translations deleted.
- New tests for the scheduler loop itself: a tick, Wake, a pass that threw,
  and dispose during a pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c5ad0c4c3f636129afe5dd1ce039185516da5621)
This commit is contained in:
Alby96 committed 2026-10-27 09:56:47 +01:00
1 parent 422f33d5f3
commit e384564784
59 files changed
+668 -264

No files matched your search

@@ -128,6 +128,31 @@ public sealed class DesktopScheduleHostTests(TestContext context)
Assert.Count(1, DatabaseBackups.List(fx.Backups, fx.DatabasePath));
}
/// <summary>
/// The first start after the upgrade: the daily loop made a copy at start once the newest was a day old, so the index
/// backup is seeded due when it is (copied in the first pass); a fresher copy waits for its first day as a new install does.
/// </summary>
[Test]
public async Task TheFirstStartAfterTheUpgradeCopiesWhenTheNewestCopyIsADayOld()
{
await using (var stale = await ScheduleFixture.CreateAsync(context))
{
Directory.CreateDirectory(stale.Backups);
File.WriteAllText(Path.Combine(stale.Backups, $"chronos-{ScheduleFixture.T0.AddDays(-7):yyyyMMdd-HHmmss}-000.db"), "copy");
await stale.StartAsync();
var backup = Assert.NotNull(await stale.Db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.IndexBackup));
Assert.Equal((ScheduleOutcome.Queued, ScheduleFixture.T0.AddDays(1)), (backup.LastOutcome!, backup.NextRun!.Value));
Assert.Equal(JobKind.Backup, Assert.NotNull(await stale.Db.Jobs.GetAsync(backup.LastJobId!.Value)).Kind);
}
await using var fresh = await ScheduleFixture.CreateAsync(context);
Directory.CreateDirectory(fresh.Backups);
File.WriteAllText(Path.Combine(fresh.Backups, $"chronos-{ScheduleFixture.T0.AddHours(-2):yyyyMMdd-HHmmss}-000.db"), "copy");
await fresh.StartAsync();
var waiting = Assert.NotNull(await fresh.Db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.IndexBackup));
Assert.Equal(((string?)null, ScheduleFixture.T0.AddDays(1)), (waiting.LastOutcome, waiting.NextRun!.Value));
}
[Test]
public async Task TheHousekeepingRemovesOldHistoryAndTrimsTheCache()
{