diff --git a/deploy/docker/docker-compose.yml b/deploy/docker/docker-compose.yml index a2d67328..8f0e1e37 100644 --- a/deploy/docker/docker-compose.yml +++ b/deploy/docker/docker-compose.yml @@ -42,11 +42,13 @@ services: # admin panel's Settings. # CHRONOS_PARALLELISM: "4" # CHRONOS_PRIORITY_QUEUE: "true" - # The log files' and the console's level: Trace, Debug, Information, Warning, Error, Critical or None - CHRONOS_LOG_LEVEL: Information + # The log files' and the console's level: Trace, Debug, Information, Warning, Error, Critical or None (default + # Information). Set here, it locks both levels: the admin panel's Settings › Logs can no longer change them. + # CHRONOS_LOG_LEVEL: Information # The log files (/data/logs) and the audit log: the console's own level, the days files are kept, the size (MB) at # which a file continues in a numbered one and that of all files (the oldest go beyond it; 0: no limit for either), - # daily or hourly files, the days audit entries are kept (0: forever) and the MB of each log in the diagnostics zip. + # daily or hourly files, the days the audit log clean-up keeps audit entries (0: forever) and the MB of each log in the + # diagnostics zip. # Set here, they can no longer be changed in the admin panel's Settings › Logs. # CHRONOS_LOG_CONSOLE_LEVEL: Warning # CHRONOS_LOG_RETENTION_DAYS: "14" diff --git a/deploy/unraid/chronos.xml b/deploy/unraid/chronos.xml index f3ea9f0f..396235af 100644 --- a/deploy/unraid/chronos.xml +++ b/deploy/unraid/chronos.xml @@ -41,13 +41,13 @@ Chronos Server - Information + - + 99 100 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index c6312ac0..4eb315cc 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -94,8 +94,8 @@ Dependencies point one way: `Core` ← `Core.Windows`, `Data`, `Protocol` ← `S | Host | Composition root | What it runs | |---|---|---| -| Chronos (desktop) | `App/Infrastructure/AppServices` | SQLite index in `%LOCALAPPDATA%\Chronos` (or `.\data` when portable, unless the copy is in a OneDrive folder); `ArchiveService` with WIC first, then managed decoders; `ProcessingService` with Media Foundation, then managed encoders; one `JobEngine` with the handlers of both; thumbnails; `ServerSession`; `SyncHost` while signed in (sync engine and agent, upload and download handlers, metered hold, editors of server sequences); the render node while opted in and signed in; update check and download (`About/UpdateCheck`, `About/UpdateDownload`, `About/UpdateFlow`: the setup, or the portable zip for a portable copy, verified against `SHA256SUMS`, resumable, cancellable, failing after 60 s without data); diagnostics bundle; the `Scheduler` on `DesktopScheduleHost`, started once the archive was reopened (an unplugged one is looked for every minute), whose system schedules replaced the rescan timer, the daily backup loop and the job-history purge; the restore staged in Settings › Advanced (`DatabaseBackups`) | -| Chronos Server | `Server/Hosting/ServerHost.Build` | Options from `server.json` + `CHRONOS_*`; PostgreSQL (or SQLite on Windows); `ArchiveModule` then `ProcessingModule` register job handler providers; `JobEngineHost` (renders only managed formats and MP4 jobs no render node can take, BRIEF §14.7); `RenderNodeService`/`RenderNodeMonitor`; `UploadService`; `VolumeSpace` (free space of the archive, the space path and `/data`, file system and mount from `/proc/self/mountinfo`; tests replace it); `EventHub` (WebSocket); embedded admin panel; LAN discovery beacon; Windows service host; `SchedulerHost` with the system schedules `archive-scan` (every 10 minutes, also once at start), `upload-cleanup` (every 30 minutes), `index-backup` (SQLite only, 03:00), `housekeeping` (job history, 04:00) and `audit-cleanup` (04:30), no other timer queues work | +| Chronos (desktop) | `App/Infrastructure/AppServices` | SQLite index in `%LOCALAPPDATA%\Chronos` (or `.\data` when portable, unless the copy is in a OneDrive folder); `ArchiveService` with WIC first, then managed decoders; `ProcessingService` with Media Foundation, then managed encoders; one `JobEngine` with the handlers of both; thumbnails; `ServerSession`; `SyncHost` while signed in (sync engine and agent, upload and download handlers, metered hold, editors of server sequences); the render node while opted in and signed in; update check and download (`About/UpdateCheck`, `About/UpdateDownload`, `About/UpdateFlow`: the setup, or the portable zip for a portable copy, verified against `SHA256SUMS`, resumable, cancellable, failing after 60 s without data); diagnostics bundle; the `Scheduler` on `DesktopScheduleHost`, started once the archive was reopened (an unplugged one is looked for every minute), which then runs the archive scan once (again when an unplugged archive is back), and whose system schedules replaced the rescan timer, the daily backup loop and the job-history purge (scans follow Settings › Analysis › After a scan at every run); the restore staged in Settings › Advanced (`DatabaseBackups`) | +| Chronos Server | `Server/Hosting/ServerHost.Build` | Options from `server.json` + `CHRONOS_*`; PostgreSQL (or SQLite on Windows); `ArchiveModule` then `ProcessingModule` register job handler providers; `JobEngineHost` (renders only managed formats and MP4 jobs no render node can take, BRIEF §14.7); `RenderNodeService`/`RenderNodeMonitor`; `UploadService`; `VolumeSpace` (free space of the archive, the space path and `/data`, file system and mount from `/proc/self/mountinfo`; tests replace it); `EventHub` (WebSocket); embedded admin panel; LAN discovery beacon; Windows service host; `SchedulerHost` with the system schedules `archive-scan` (every 10 minutes, also once at start), `upload-cleanup` (every 6 hours), `index-backup` (SQLite only, 03:00), `housekeeping` (job history, 04:00) and `audit-cleanup` (04:30; its age limit is Settings › Logs' audit retention, 0 by default: off, the audit log kept), no other timer queues work | | Chronos Uploader | `Uploader/App.xaml.cs` | `ChronosClient`, persisted queue, watch folders; no database | | Chronos Setup | `Setup/Program` | TPK1 payload extraction, registry, shortcuts, file types named in setup's language, silent mode, uninstaller; only what starts a program its log or payload lists is changed: Windows services of those programs stopped once the programs have closed, started again (also after a failure) or deleted through the Service Control Manager (an elevated `/SERVICES … /NAMES` step when needed), sign-in entries of those programs moved to the program an upgrade renamed or removed, shared shortcuts handed to the product that keeps the program; the Server only for all users inside Program Files; "Remove my data" limited to the programs no other installed product uses | diff --git a/i18n/en/Admin.resx b/i18n/en/Admin.resx index 1a172f32..1c3b48b9 100644 --- a/i18n/en/Admin.resx +++ b/i18n/en/Admin.resx @@ -434,7 +434,7 @@ When it runs; times are in the server's time zone ({0}) About Keep audit (days) - Days audit entries are kept before the housekeeping deletes them; 0: forever + Age limit of the Audit log clean-up schedule: older audit entries are deleted; 0: kept forever Chunk size (MiB) Size of each upload chunk; smaller chunks resume faster on poor links Console level diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 55622c86..b5a51a15 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -337,7 +337,6 @@ A run missed while Chronos was closed happens once when it starts Create the schedule Day 1 to 28, which every month has - Sequences the scan indexes also get a deep analysis A deep analysis of the sequences without one, instead of a light one Lists what the maintenance would do without changing anything Off, the schedule never runs by itself diff --git a/i18n/it/Admin.it.resx b/i18n/it/Admin.it.resx index 5866a015..02b185ba 100644 --- a/i18n/it/Admin.it.resx +++ b/i18n/it/Admin.it.resx @@ -433,7 +433,7 @@ Quando parte; gli orari sono nel fuso orario del server ({0}) Informazioni Conserva controllo (giorni) - Giorni di conservazione delle voci di controllo prima che la manutenzione le elimini; 0: per sempre + Limite di età della pianificazione Pulizia registro controllo: le voci più vecchie vengono eliminate; 0: conservate per sempre Dimensione blocco (MiB) Dimensione di ogni blocco di caricamento; blocchi piccoli riprendono prima su linee lente Livello console diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 987f1e70..2dead7a8 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -336,7 +336,6 @@ Un'esecuzione persa mentre Chronos era chiuso avviene una volta all'avvio Crea la pianificazione Giorno da 1 a 28, che ogni mese ha - Le sequenze che la scansione indicizza ricevono anche un'analisi approfondita Un'analisi approfondita delle sequenze che non ne hanno una, invece di una rapida Elenca cosa farebbe la manutenzione senza cambiare niente Disattivata, la pianificazione non viene mai eseguita da sola diff --git a/src/Chronos.App/Infrastructure/AppServices.cs b/src/Chronos.App/Infrastructure/AppServices.cs index 17255d00..e2e25eec 100644 --- a/src/Chronos.App/Infrastructure/AppServices.cs +++ b/src/Chronos.App/Infrastructure/AppServices.cs @@ -288,10 +288,11 @@ public sealed class AppServices : IAsyncDisposable /// /// At start, off the UI thread: reopens the archive at Settings › Archive's folder (a moved one relinked, interrupted - /// renames finished), then starts the schedules, whose first pass settles the runs missed while Chronos was closed. An - /// archive whose archive.json is not there (an unplugged drive) is looked for every until - /// it is back, then the schedules look at once for a due run; unless the folder changed meanwhile: whatever changed it - /// opened the new archive. The app's exit waits for this on the UI thread. + /// renames finished), then starts the schedules, whose first pass settles the runs missed while Chronos was closed, and + /// runs the archive scan once, as the rescans did at start (). An archive whose archive.json is + /// not there (an unplugged drive) is looked for every until it is back, then scanned and the + /// schedules look at once for a due run; unless the folder changed meanwhile: whatever changed it opened the new + /// archive. The app's exit waits for this on the UI thread. /// private async Task RunSchedulesAsync(CancellationToken ct) { @@ -299,13 +300,19 @@ public sealed class AppServices : IAsyncDisposable try { if (reopen is not null && await ReopenAsync(reopen, ct).ConfigureAwait(false)) reopen = null; + var started = SchedulerTime.GetUtcNow(); await StartSchedulerAsync(ct).ConfigureAwait(false); - if (reopen is null) return; + if (reopen is null) + { + await ScanNowAsync(started, ct).ConfigureAwait(false); + return; + } using var timer = new PeriodicTimer(ReopenInterval); while (await timer.WaitForNextTickAsync(ct).ConfigureAwait(false)) { if (!string.Equals(reopen, Settings.LastArchivePath, StringComparison.OrdinalIgnoreCase)) return; if (!await ReopenAsync(reopen, ct).ConfigureAwait(false)) continue; + await ScanNowAsync(null, ct).ConfigureAwait(false); Scheduler?.Wake(); return; } @@ -324,6 +331,23 @@ public sealed class AppServices : IAsyncDisposable } } + /// + /// Runs the archive scan schedule once now when it is enabled (owner review 2, R10: the archive was opened or is back), + /// unless it ran since (the first pass fired it) or its scan is still pending. + /// + private async Task ScanNowAsync(DateTimeOffset? since, CancellationToken ct) + { + if (Scheduler is not { } scheduler) return; + try + { + await scheduler.RunSystemNowAsync(DesktopScheduleHost.ArchiveScan, since, ct).ConfigureAwait(false); + } + catch (Exception ex) when (ex is DatabaseException or IOException or InvalidOperationException) + { + Log.Warning("schedules", "The archive scan could not be run now; its schedule runs the next one", ex); + } + } + /// /// Starts on this PC's engine: it seeds the system schedules and runs its first pass before /// turns true. Without an engine, or when the schedules cannot be read, there is none. diff --git a/src/Chronos.App/Jobs/DesktopScheduleHost.cs b/src/Chronos.App/Jobs/DesktopScheduleHost.cs index 5d704b9d..bd9a344e 100644 --- a/src/Chronos.App/Jobs/DesktopScheduleHost.cs +++ b/src/Chronos.App/Jobs/DesktopScheduleHost.cs @@ -21,7 +21,8 @@ namespace Chronos.App.Jobs; /// drive). The system schedules stand for the timers the desktop used to run out of sight: the archive scan (its interval /// carried over from the former Settings › Archive › Rescan every, , once: /// a row that exists keeps the user's edits), the daily index backup, and the housekeeping clean-up at 04:00 (job history, -/// cache trim). Thread-safe: the scheduler calls it from its loop. +/// cache trim). Scans give what they find a deep analysis as Settings › Analysis › After a scan says at each run +/// (), like the scans started by hand. Thread-safe: the scheduler calls it from its loop. /// public sealed class DesktopScheduleHost(AppSettings settings, Func database, Func archives) : IScheduleHost { @@ -43,7 +44,7 @@ public sealed class DesktopScheduleHost(AppSettings settings, Func SystemSchedules => [ new(ArchiveScan, "Archive scan", ScheduleActions.Scan, ScheduleRecurrence.Interval(ScanMinutes(settings), RecurrenceUnit.Minutes), - new ScheduleParametersDto(Force: false, Deep: settings.DeepAnalysisAfterScan), CatchUp: false), + new ScheduleParametersDto(Force: false), CatchUp: false), new(IndexBackup, "Index backup", ScheduleActions.Backup, ScheduleRecurrence.Interval(1, RecurrenceUnit.Days), new ScheduleParametersDto(Keep: DatabaseBackups.Keep)), new(Housekeeping, "Housekeeping", ScheduleActions.Cleanup, ScheduleRecurrence.DailyAt(HousekeepingTime), @@ -83,6 +84,9 @@ public sealed class DesktopScheduleHost(AppSettings settings, FuncThe desktop runs every action its engine has a handler for. public string? Unavailable(string action) => null; + + /// Settings › Analysis › After a scan, read at every run: a scheduled scan follows it as a scan started by hand does. + public bool DeepAnalysisAfterScan => settings.DeepAnalysisAfterScan; } /// diff --git a/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs b/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs index 759b969c..51964c5e 100644 --- a/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs +++ b/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs @@ -268,7 +268,8 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel // ---------------- Parameters ---------------- public bool ShowsForce => _action.Name is ScheduleActions.Scan or ScheduleActions.Thumbnails or ScheduleActions.Proxies; - public bool ShowsDeep => _action.Name is ScheduleActions.Scan or ScheduleActions.Analysis; + /// Analysis only: a scan's deep analysis follows Settings › Analysis › After a scan at every run. + public bool ShowsDeep => _action.Name == ScheduleActions.Analysis; public bool ShowsOlderThan => _action.Name is ScheduleActions.Verify or ScheduleActions.Cleanup; public bool ShowsPercent => _action.Name == ScheduleActions.Verify; public bool ShowsDryRun => _action.Name == ScheduleActions.Maintenance; @@ -294,7 +295,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel set => Set(ref _deep, value); } - public string DeepToolTip => Loc.L(_action.Name == ScheduleActions.Scan ? "Tooltips.Jobs.Editor.DeepAfterScan" : "Tooltips.Jobs.Editor.DeepAnalysis"); + public string DeepToolTip => Loc.L("Tooltips.Jobs.Editor.DeepAnalysis"); public bool DryRun { diff --git a/src/Chronos.Data/Scheduling/IScheduleHost.cs b/src/Chronos.Data/Scheduling/IScheduleHost.cs index e01f27bd..a308af17 100644 --- a/src/Chronos.Data/Scheduling/IScheduleHost.cs +++ b/src/Chronos.Data/Scheduling/IScheduleHost.cs @@ -29,6 +29,12 @@ public interface IScheduleHost /// The names of the clean-up steps this host's jobs run (normally those of ArchiveService.CleanupSteps). IReadOnlyList CleanupSteps { get; } + /// + /// Whether a scan whose schedule leaves its deep parameter unset gives the sequences it finds a deep analysis. + /// Read at every run, so the desktop's scans follow Settings › Analysis › After a scan as it is then; false on the server. + /// + bool DeepAnalysisAfterScan { get; } + /// /// Why this host does not run (a short code, e.g. not-here), or null when it may. Asked /// before the scheduler's own checks (), for the action list and at every run. diff --git a/src/Chronos.Data/Scheduling/ScheduleActions.cs b/src/Chronos.Data/Scheduling/ScheduleActions.cs index 7151ce2b..044d5ec6 100644 --- a/src/Chronos.Data/Scheduling/ScheduleActions.cs +++ b/src/Chronos.Data/Scheduling/ScheduleActions.cs @@ -36,7 +36,10 @@ public sealed record ScheduleActionContext(ChronosDatabase Database, IScheduleHo /// public static class ScheduleActions { - /// Incremental scan of the archive (force: a full one; deep: deep analysis of what it indexes). + /// + /// Incremental scan of the archive (force: a full one; deep: deep analysis of what it indexes; unset, as the + /// host says at the run, ). + /// public const string Scan = "scan"; /// Integrity check of the originals, the least recently verified first (olderThanDays, percent). @@ -96,7 +99,8 @@ public static class ScheduleActions /// The parameters a new schedule of starts with. public static ScheduleParametersDto Defaults(string action) => action switch { - Scan => new(Force: false, Deep: false), + // No deep: a scan follows the host's choice at run time (IScheduleHost.DeepAnalysisAfterScan) unless its schedule sets one. + Scan => new(Force: false), Verify => new(OlderThanDays: 30, Percent: 100), Thumbnails or Proxies => new(Force: false), Analysis => new(Deep: false), @@ -116,7 +120,7 @@ public static class ScheduleActions var d = Defaults(action); return action switch { - Scan => new(Force: p.Force ?? d.Force, Deep: p.Deep ?? d.Deep), + Scan => new(Force: p.Force ?? d.Force, Deep: p.Deep), Verify => new(OlderThanDays: p.OlderThanDays ?? d.OlderThanDays, Percent: p.Percent ?? d.Percent), Thumbnails or Proxies => new(Force: p.Force ?? d.Force), Analysis => new(Deep: p.Deep ?? d.Deep), @@ -189,7 +193,7 @@ public static class ScheduleActions { case Scan: return await PendingAsync(db, [JobKind.Scan, JobKind.Rebuild], archive, cancellationToken).ConfigureAwait(false) - ?? ScheduleResolution.Queue([ArchiveJobs.Scan(archive, full: p.Force == true, deepAnalysis: p.Deep == true)]); + ?? ScheduleResolution.Queue([ArchiveJobs.Scan(archive, full: p.Force == true, deepAnalysis: p.Deep ?? context.Host.DeepAnalysisAfterScan)]); case Verify: return await PendingAsync(db, [JobKind.Verify], archive, cancellationToken).ConfigureAwait(false) ?? await VerifyAsync(context, archive, p, cancellationToken).ConfigureAwait(false); diff --git a/src/Chronos.Data/Scheduling/Scheduler.cs b/src/Chronos.Data/Scheduling/Scheduler.cs index f82c0c7a..fd6f8c79 100644 --- a/src/Chronos.Data/Scheduling/Scheduler.cs +++ b/src/Chronos.Data/Scheduling/Scheduler.cs @@ -158,6 +158,19 @@ public sealed class Scheduler : IAsyncDisposable return new ScheduleRunDto(dto, fire.Outcome, fire.JobId); } + /// + /// Runs the system schedule now (, which skips while its work is + /// pending) when it is enabled and has not run since ; null when it did not run. The hosts' archive + /// scan once at start, as their polling did, and on the desktop when its archive is opened again (owner review 2, R10). + /// + public async Task RunSystemNowAsync(string systemKey, DateTimeOffset? since = null, CancellationToken cancellationToken = default) + { + _ = RequireHost(); + if (await _db.Schedules.GetBySystemKeyAsync(systemKey, cancellationToken).ConfigureAwait(false) is not { Enabled: true } schedule + || schedule.LastRun >= since) return null; + return await RunNowAsync(schedule.Id, null, cancellationToken).ConfigureAwait(false); + } + /// The schedules (system ones first), the actions with their availability here, the host's time zone and clean-up steps. public async Task ListAsync(CancellationToken cancellationToken = default) { diff --git a/src/Chronos.Server/Api/AdminEndpoints.cs b/src/Chronos.Server/Api/AdminEndpoints.cs index 3aa5e951..d6a9783d 100644 --- a/src/Chronos.Server/Api/AdminEndpoints.cs +++ b/src/Chronos.Server/Api/AdminEndpoints.cs @@ -74,8 +74,9 @@ public static class AdminEndpoints } private static async Task SaveSettingsAsync(HttpContext context, Caller caller, ServerSettingsDto request, ServerSettingsStore store, ServerOptions options, - AuditLog audit, JobEngineHost jobs) + AuditLog audit, JobEngineHost jobs, SchedulerHost schedules) { + var auditDays = options.AuditRetentionDays; switch (store.Save(request)) { case ("setting_locked", var setting): @@ -85,6 +86,8 @@ public static class AdminEndpoints } // A priority queue turned on, or a level raised, may make the running job yield at once. jobs.Engine.Wake(); + // The audit retention is the audit clean-up schedule's age limit: a new one goes there (owner review 2, R10, R11). + if (options.AuditRetentionDays != auditDays) await schedules.ApplyAuditRetentionAsync(options.AuditRetentionDays, context.RequestAborted); await audit.WriteAsync(caller, context, "server_settings", "server", null, request.ServerName); return Results.Json(store.Current() with { ProxyWarning = AdminPanel.BypassesProxy(context, options) }, ProtocolJson.Default.ServerSettingsDto); } diff --git a/src/Chronos.Server/Configuration/ServerSettingsStore.cs b/src/Chronos.Server/Configuration/ServerSettingsStore.cs index dc809dd4..4513a4e5 100644 --- a/src/Chronos.Server/Configuration/ServerSettingsStore.cs +++ b/src/Chronos.Server/Configuration/ServerSettingsStore.cs @@ -15,7 +15,9 @@ namespace Chronos.Server.Configuration; /// edited keys; secrets and environment values are never written) and applies what can change while running, the /// parallelism and the priority queue included (owner review 1), and the log settings through /// (owner review 2, R11); ports, TLS and chunk size wait for a restart. Job history is what the housekeeping system -/// schedule is reset to (owner review 2, R10): the schedule's own value applies. +/// schedule is reset to (owner review 2, R10): the schedule's own value applies. The audit retention is what the audit +/// clean-up schedule is reset to, and saving a new one also sets that schedule's age limit (the endpoint does it through +/// SchedulerHost.ApplyAuditRetentionAsync). /// public sealed class ServerSettingsStore(ServerOptions options, ServerLogging logging) { diff --git a/src/Chronos.Server/Jobs/SchedulerHost.cs b/src/Chronos.Server/Jobs/SchedulerHost.cs index 8b856938..92603b8f 100644 --- a/src/Chronos.Server/Jobs/SchedulerHost.cs +++ b/src/Chronos.Server/Jobs/SchedulerHost.cs @@ -1,6 +1,7 @@ using Chronos.Data; using Chronos.Data.Scheduling; using Chronos.Protocol; +using Chronos.Server.Configuration; namespace Chronos.Server.Jobs; @@ -10,7 +11,8 @@ namespace Chronos.Server.Jobs; /// it seeds the system schedules and settles missed runs (), applies the age limits that /// environment variables fix (), and runs the archive scan once in the /// background, as the former polling did, so the photos of an adopted folder are indexed without waiting for its first -/// interval (only while that schedule is enabled). +/// interval (only while that schedule is enabled). The audit retention saved in Settings › Logs becomes the audit +/// clean-up's age limit (). /// public sealed class SchedulerHost : IHostedService { @@ -52,31 +54,43 @@ public sealed class SchedulerHost : IHostedService } /// - /// Puts the age limits environment variables fix into their system schedules (also enabling one that has a limit now, - /// or disabling it at 0, which keeps everything); a schedule already holding the value is left as the user set it. + /// Puts the audit retention just saved in Settings › Logs () into the + /// audit clean-up schedule, its one source of truth (owner review 2, R10, R11): enabled with a limit, off at 0, which + /// keeps everything. A schedule already holding the value is left as the user set it. /// + public Task ApplyAuditRetentionAsync(int days, CancellationToken cancellationToken = default) => + ApplyAgeAsync(ServerScheduleHost.AuditCleanup, days, "Settings › Logs", cancellationToken); + + /// The age limits environment variables fix, put into their system schedules at every start. private async Task ApplyLockedAgesAsync(CancellationToken cancellationToken) { foreach (var system in Host.SystemSchedules) { - if (Host.LockedAgeOf(system.SystemKey) is not { } locked) continue; - if (await _db.Schedules.GetBySystemKeyAsync(system.SystemKey, cancellationToken) is not { } row) continue; - var parameters = ScheduleMapping.Parameters(row); - if (parameters.OlderThanDays == locked.Days) continue; - var result = await Scheduler.UpdateAsync(row.Id, new UpdateScheduleRequest(Parameters: parameters with { OlderThanDays = locked.Days }, Enabled: locked.Days > 0), - cancellationToken); - if (result.Problem is { } problem) _logger.LogWarning("{Variable} could not be applied to the {Schedule} schedule ({Problem})", locked.Variable, row.Name, problem); - else _logger.LogInformation("{Variable} sets the {Schedule} schedule to {Days} day(s)", locked.Variable, row.Name, locked.Days); + if (Host.LockedAgeOf(system.SystemKey) is { } locked) await ApplyAgeAsync(system.SystemKey, locked.Days, locked.Variable, cancellationToken); } } + /// + /// Sets the age limit of the system schedule to , enabling it when it + /// has a limit now and disabling it at 0; nothing when it already holds the value. + /// + private async Task ApplyAgeAsync(string systemKey, int days, string source, CancellationToken cancellationToken) + { + if (await _db.Schedules.GetBySystemKeyAsync(systemKey, cancellationToken) is not { } row) return; + var parameters = ScheduleMapping.Parameters(row); + if (parameters.OlderThanDays == days) return; + var result = await Scheduler.UpdateAsync(row.Id, new UpdateScheduleRequest(Parameters: parameters with { OlderThanDays = days }, Enabled: days > 0), + cancellationToken); + if (result.Problem is { } problem) _logger.LogWarning("{Source} could not be applied to the {Schedule} schedule ({Problem})", source, row.Name, problem); + else _logger.LogInformation("{Source} sets the {Schedule} schedule to {Days} day(s)", source, row.Name, days); + } + /// The archive scan's run at start, unless the first pass already fired it or it is disabled. private async Task ScanAtStartAsync(DateTimeOffset started, CancellationToken cancellationToken) { try { - if (await _db.Schedules.GetBySystemKeyAsync(ServerScheduleHost.ArchiveScan, cancellationToken) is not { Enabled: true } scan || scan.LastRun >= started) return; - await Scheduler.RunNowAsync(scan.Id, null, cancellationToken); + await Scheduler.RunSystemNowAsync(ServerScheduleHost.ArchiveScan, started, cancellationToken); } catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { diff --git a/src/Chronos.Server/Jobs/ServerScheduleHost.cs b/src/Chronos.Server/Jobs/ServerScheduleHost.cs index a0e0430b..570203c5 100644 --- a/src/Chronos.Server/Jobs/ServerScheduleHost.cs +++ b/src/Chronos.Server/Jobs/ServerScheduleHost.cs @@ -16,7 +16,7 @@ public sealed record LockedAge(string Setting, string Variable, int Days); /// What the server tells its (owner review 2, R10): the container's time zone (TZ), the archive it /// serves with the settings another writer put into archive.json (refreshed at every run, as the former polling did), the /// server's own clean-up steps, and its system schedules, which stand for every timer it ran out of sight before: the -/// archive scan every 10 minutes (no catch-up), the uploads sweep every 30 minutes, the nightly copy of an SQLite index, +/// archive scan every 10 minutes (no catch-up), the uploads sweep every 6 hours, the nightly copy of an SQLite index, /// the job history and the audit log retentions. They are seeded from once (the user's edits /// stay) and reset to the options as they are then. /// @@ -31,8 +31,11 @@ public sealed class ServerScheduleHost : IScheduleHost /// Minutes between two archive scans (the desktop's rhythm, as the polling had). public const int ScanMinutes = 10; - /// Minutes between two sweeps of abandoned uploads (as the upload maintenance had). - public const int UploadSweepMinutes = 30; + /// + /// Hours between two sweeps of abandoned uploads: rare enough to keep the job history readable (four clean-up jobs a + /// day); an idle upload still expires after , at most this much later. + /// + public const int UploadSweepHours = 6; private readonly ChronosDatabase _db; private readonly ServerOptions _options; @@ -67,7 +70,7 @@ public sealed class ServerScheduleHost : IScheduleHost { // A missed scan is not caught up: the next one comes within minutes and SchedulerHost scans once at start. new(ArchiveScan, "Archive scan", ScheduleActions.Scan, ScheduleRecurrence.Interval(ScanMinutes, RecurrenceUnit.Minutes), CatchUp: false), - new(UploadCleanup, "Upload clean-up", ScheduleActions.Cleanup, ScheduleRecurrence.Interval(UploadSweepMinutes, RecurrenceUnit.Minutes), + new(UploadCleanup, "Upload clean-up", ScheduleActions.Cleanup, ScheduleRecurrence.Interval(UploadSweepHours, RecurrenceUnit.Hours), new ScheduleParametersDto(OlderThanDays: UploadMaintenance.FinishedRetentionDays, Steps: [UploadCleanupStep.StepName])), }; // PostgreSQL is backed up with its own tools (BRIEF §6.2): no schedule that could never run. @@ -107,6 +110,9 @@ public sealed class ServerScheduleHost : IScheduleHost /// The server runs every action it has a handler for; the scheduler finds the rest out itself. public string? Unavailable(string action) => null; + /// The server has no such setting: a scan schedule's own deep parameter decides, off when unset. + public bool DeepAnalysisAfterScan => false; + /// /// The age limit of the system schedule that an environment variable fixes /// (CHRONOS_AUDIT_RETENTION_DAYS for ); null when the schedule's own value applies. diff --git a/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs b/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs index 88adc174..a9d1886a 100644 --- a/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs +++ b/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs @@ -35,14 +35,14 @@ public sealed class AppServicesTests await new ArchiveService(setup).CreateAsync(root, "Exit"); var services = new AppServices(environment, new AppSettings { Language = "en", LastArchivePath = root }, () => { }, new NoDialogs()); await services.OpenAsync(environment.DatabasePath); - // The archive was reopened, then the schedules started (owner review 2, R10): its scan schedule queues a scan of it. + // The archive was reopened, then the schedules started (owner review 2, R10) and its scan schedule ran at once, + // as the rescans did at start: a scan of it is queued without waiting for the interval. Assert.True(await services.SchedulerReady, "the schedules started"); var scan = Assert.NotNull(await services.Database!.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.ArchiveScan)); - Assert.Equal(ScheduleOutcome.Queued, (await services.Scheduler!.RunNowAsync(scan.Id, null))?.Outcome); var until = DateTime.UtcNow + TimeSpan.FromSeconds(30); - while ((await services.Database!.Jobs.ListAsync(null, JobKind.Scan)).Items.Count == 0) + while (!(await services.Database!.Jobs.ListAsync(null, JobKind.Scan)).Items.Any(j => j.ScheduleId == scan.Id)) { - Assert.True(DateTime.UtcNow < until, "no rescan queued"); + Assert.True(DateTime.UtcNow < until, "no scan at start"); await Task.Delay(50); } diff --git a/tests/Chronos.App.Tests/Jobs/DesktopScheduleHostTests.cs b/tests/Chronos.App.Tests/Jobs/DesktopScheduleHostTests.cs index a04ede60..977f135c 100644 --- a/tests/Chronos.App.Tests/Jobs/DesktopScheduleHostTests.cs +++ b/tests/Chronos.App.Tests/Jobs/DesktopScheduleHostTests.cs @@ -26,7 +26,8 @@ public sealed class DesktopScheduleHostTests(TestContext context) var scan = Assert.NotNull(await fx.Db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.ArchiveScan)); Assert.Equal(("every:30m", false, JobPriority.Background, true, ScheduleActions.Scan), (scan.Recurrence, scan.CatchUp, scan.Priority, scan.Enabled, scan.Action)); - Assert.Equal(true, ScheduleMapping.Parameters(scan).Deep); + // The deep analysis is not frozen into the schedule: each run reads Settings › Analysis › After a scan. + Assert.Null(ScheduleMapping.Parameters(scan).Deep); Assert.Equal(fx.Clock.Now.AddMinutes(30), scan.NextRun); // The user edits the schedule in Jobs › Scheduled; the old setting changes (or never changes again): the next @@ -43,6 +44,52 @@ public sealed class DesktopScheduleHostTests(TestContext context) Assert.Equal("every:5m", (await fx.Db.Schedules.GetAsync(scan.Id))!.Recurrence); } + /// + /// Owner review 2, R10: the scheduled scans follow Settings › Analysis › After a scan as it is at each run, like the + /// scans started by hand, so that checkbox's tooltip stays true; and the archive is scanned right after it was opened + /// (once per start, and again when an unplugged archive is back), as the rescans did. + /// + [Test] + public async Task TheScanRunsAtOnceAndFollowsTheDeepAnalysisSettingAtEachRun() + { + var settings = new AppSettings { Language = "en", DeepAnalysisAfterScan = false }; + await using var fx = await ScheduleFixture.CreateAsync(context, settings); + var archive = await fx.Archives.CreateAsync(Path.Combine(fx.Folder, "archive"), "archive"); + settings.LastArchivePath = archive.RootPath; + var started = fx.Clock.Now; + var scheduler = await fx.StartAsync(); + + // Right after the start, not one interval later. + var first = Assert.NotNull(await scheduler.RunSystemNowAsync(DesktopScheduleHost.ArchiveScan, started)); + Assert.Equal(ScheduleOutcome.Queued, first.Outcome); + Assert.False(await DeepAsync(fx, first.JobId!.Value)); + Assert.Null(await scheduler.RunSystemNowAsync(DesktopScheduleHost.ArchiveScan, started)); + + // The setting changes after the schedule was seeded: the next run follows it. + settings.DeepAnalysisAfterScan = true; + await fx.Db.Jobs.SetStateAsync(first.JobId!.Value, JobState.Done); + var second = Assert.NotNull(await scheduler.RunSystemNowAsync(DesktopScheduleHost.ArchiveScan)); + Assert.Equal(ScheduleOutcome.Queued, second.Outcome); + Assert.True(await DeepAsync(fx, second.JobId!.Value)); + Assert.True(fx.Host.DeepAnalysisAfterScan); + + // The editor offers no deep switch for a scan (only for an analysis), so a scan schedule never freezes it. + using var vm = await fx.ViewModelAsync(); + vm.NewCommand.Execute(null); + var editor = Assert.NotNull(vm.Editor); + editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Scan); + Assert.True(editor.ShowsForce && !editor.ShowsDeep, "a scan's switches: a full scan only"); + } + + /// Whether the scan job gives what it finds a deep analysis. + private static async Task DeepAsync(ScheduleFixture fx, Guid id) + { + var job = Assert.NotNull(await fx.Db.Jobs.GetAsync(id)); + Assert.Equal(JobKind.Scan, job.Kind); + using var parameters = System.Text.Json.JsonDocument.Parse(job.ParametersJson!); + return parameters.RootElement.GetProperty("deepAnalysis").GetBoolean(); + } + [Test] public void TheFormerIntervalIsClampedToWhatAnIntervalAccepts() { diff --git a/tests/Chronos.Data.Tests/Scheduling/SchedulerTests.cs b/tests/Chronos.Data.Tests/Scheduling/SchedulerTests.cs index f2040553..64c12385 100644 --- a/tests/Chronos.Data.Tests/Scheduling/SchedulerTests.cs +++ b/tests/Chronos.Data.Tests/Scheduling/SchedulerTests.cs @@ -41,6 +41,8 @@ internal sealed class TestScheduleHost(Archive? archive) : IScheduleHost public IReadOnlyList CleanupSteps { get; set; } = ["job-history", "audit", "trash-report"]; + public bool DeepAnalysisAfterScan { get; set; } + public ValueTask GetArchiveAsync(CancellationToken cancellationToken) => ValueTask.FromResult(Archive); public string? Unavailable(string action) => Refused.GetValueOrDefault(action); @@ -431,6 +433,70 @@ public sealed class SchedulerTests(TestContext context) Assert.Equal(ScheduleOutcome.Unavailable, (await other.RunNowAsync((await CreateAsync(other, ScheduleActions.Analysis)).Id, null, Ct))!.Outcome); } + /// + /// Owner review 2, R10: both hosts scan right after they start (the desktop also when its archive is back), as their + /// polling did, through the archive scan system schedule: once, only while it is enabled, never twice for one start. + /// + [Test] + public async Task ASystemScheduleRunsNowOnceWhenEnabledAndNotRunSince() + { + await using var fx = await ArchiveFixture.CreateAsync(context); + await using var engine = Engine(fx); + var clock = new ScheduleClock(T0); + var host = new TestScheduleHost(fx.Archive); + host.Systems.Add(new SystemSchedule("archive-scan", "Archive scan", ScheduleActions.Scan, ScheduleRecurrence.Interval(10, RecurrenceUnit.Minutes), CatchUp: false)); + await using var scheduler = await StartAsync(fx.Db, engine, host, clock); + Assert.Null(await scheduler.RunSystemNowAsync("no-such-key", null, Ct)); + + // Right after the start: the scan is queued, without waiting for its first interval. + var started = clock.Now; + var run = Assert.NotNull(await scheduler.RunSystemNowAsync("archive-scan", started, Ct)); + Assert.Equal(ScheduleOutcome.Queued, run.Outcome); + var job = (await fx.Db.Jobs.GetAsync(run.JobId!.Value, Ct))!; + Assert.Equal((JobKind.Scan, JobPriority.Background, (Guid?)run.Schedule.Id), (job.Kind, job.Priority, job.ScheduleId)); + Assert.Equal(T0.AddMinutes(10), run.Schedule.NextRun); + // It ran since that start: not again. Asked again later (the archive is back), its pending scan is not queued twice. + Assert.Null(await scheduler.RunSystemNowAsync("archive-scan", started, Ct)); + Assert.Equal(ScheduleOutcome.SkippedPending, (await scheduler.RunSystemNowAsync("archive-scan", null, Ct))!.Outcome); + Assert.Count(1, await fx.Db.Jobs.ListByScheduleAsync(run.Schedule.Id, cancellationToken: Ct)); + + // Turned off, it does not run at start. + Assert.Null((await scheduler.UpdateAsync(run.Schedule.Id, new UpdateScheduleRequest(Enabled: false), Ct)).Problem); + await fx.Db.Jobs.SetStateAsync(job.Id, JobState.Done, cancellationToken: Ct); + Assert.Null(await scheduler.RunSystemNowAsync("archive-scan", null, Ct)); + } + + /// + /// Owner review 2, R10: a scan whose schedule leaves deep unset follows the host at every run (the desktop's Settings › + /// Analysis › After a scan as it is then), one that sets it keeps its own choice. + /// + [Test] + public async Task AScanWithoutItsOwnDeepFollowsTheHostAtEveryRun() + { + await using var fx = await ArchiveFixture.CreateAsync(context); + await using var engine = Engine(fx); + var host = new TestScheduleHost(fx.Archive); + await using var scheduler = await StartAsync(fx.Db, engine, host, new ScheduleClock(T0)); + var follows = await CreateAsync(scheduler, ScheduleActions.Scan); + Assert.Null(follows.Parameters.Deep); + var own = await CreateAsync(scheduler, ScheduleActions.Scan, parameters: new ScheduleParametersDto(Deep: false)); + Assert.Equal(false, own.Parameters.Deep); + + async Task DeepAsync(ScheduleDto schedule) + { + var resolution = await ScheduleActions.ResolveAsync(new ScheduleActionContext(fx.Db, host, _ => true, T0), schedule.Action, schedule.Parameters, Ct); + var request = resolution.Requests.Single(); + return System.Text.Json.JsonSerializer.Deserialize(request.ParametersJson!, ArchiveJobJson.Default.ScanParameters)!.DeepAnalysis; + } + Assert.False(await DeepAsync(follows)); + host.DeepAnalysisAfterScan = true; + Assert.True(await DeepAsync(follows)); + Assert.False(await DeepAsync(own)); + // The queued job carries it too. + var job = (await fx.Db.Jobs.GetAsync((await scheduler.RunNowAsync(follows.Id, null, Ct))!.JobId!.Value, Ct))!; + Assert.True(ArchiveJobJson.Read(job, ArchiveJobJson.Default.ScanParameters, new ScanParameters(false)).DeepAnalysis); + } + private static async Task IngestAsync(ArchiveFixture fx, string key, int seed) { var staged = fx.Stage(ArchiveFixture.Start.AddMinutes(seed), seed); diff --git a/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs b/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs index 1243072f..2ad206ce 100644 --- a/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs +++ b/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs @@ -38,7 +38,8 @@ public sealed class ScheduleEndpointTests(TestContext context) Assert.Equal(("scan", new RecurrenceDto("every", 10, "minutes"), false, "background", true), (scan.Action, scan.Recurrence, scan.CatchUp, scan.Priority, scan.Enabled)); Assert.NotNull(scan.NextRun); var uploads = SystemRow(list, ServerScheduleHost.UploadCleanup); - Assert.Equal(("cleanup", new RecurrenceDto("every", 30, "minutes"), true, (int?)90), (uploads.Action, uploads.Recurrence, uploads.CatchUp, uploads.Parameters.OlderThanDays)); + // Every 6 hours, not more often: four clean-up jobs a day keep the job history readable. + Assert.Equal(("cleanup", new RecurrenceDto("every", 6, "hours"), true, (int?)90), (uploads.Action, uploads.Recurrence, uploads.CatchUp, uploads.Parameters.OlderThanDays)); Assert.SequenceEqual([UploadCleanupStep.StepName], uploads.Parameters.Steps!); var backup = SystemRow(list, ServerScheduleHost.IndexBackup); Assert.Equal(("backup", new RecurrenceDto("daily", Time: "03:00"), true, (int?)3), (backup.Action, backup.Recurrence, backup.CatchUp, backup.Parameters.Keep)); @@ -46,7 +47,8 @@ public sealed class ScheduleEndpointTests(TestContext context) Assert.Equal((new RecurrenceDto("daily", Time: "04:00"), (int?)90), (history.Recurrence, history.Parameters.OlderThanDays)); Assert.SequenceEqual(["job-history"], history.Parameters.Steps!); var audit = SystemRow(list, ServerScheduleHost.AuditCleanup); - Assert.Equal((new RecurrenceDto("daily", Time: "04:30"), (int?)365, true), (audit.Recurrence, audit.Parameters.OlderThanDays, audit.Enabled)); + // The audit log is kept forever by default: no deletion after an upgrade. + Assert.Equal((new RecurrenceDto("daily", Time: "04:30"), (int?)0, false), (audit.Recurrence, audit.Parameters.OlderThanDays, audit.Enabled)); Assert.SequenceEqual(["audit"], audit.Parameters.Steps!); // Every action, with whether this server runs it: without the processing module there is no analysis. @@ -213,6 +215,58 @@ public sealed class ScheduleEndpointTests(TestContext context) Assert.Equal((int?)30, (await reset.ReadAsync(ProtocolJson.Default.ScheduleDto)).Parameters.OlderThanDays); } + /// + /// Owner review 2, R10 and R11: the audit retention has one source of truth, the audit clean-up schedule's age limit. The + /// field of Settings › Logs sets it (and turns the schedule on, or off at 0), Reset goes back to it, and at 0 the audit + /// step deletes nothing. + /// + [Test] + public async Task TheAuditRetentionOfTheSettingsIsTheAgeLimitOfTheAuditCleanUp() + { + await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); + var admin = await server.AdminAsync(); + var audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup); + Assert.Equal(((int?)0, false), (audit.Parameters.OlderThanDays, audit.Enabled)); + + // At 0 a run (also of the disabled schedule, on request) keeps the whole audit log. + var entries = (await server.Database.Audit.ListByActionsAsync(null, [], 1000, null, Ct)).Items.Select(e => e.Id).ToList(); + Assert.True(entries.Count > 0, "the sign-in left audit entries"); + var run = await RunAsync(admin, audit.Id); + var job = await JobApiTests.WaitForAsync(admin, run.JobId!.Value, "done"); + Assert.Contains("Audit log kept in full", job.LogTail); + var kept = (await server.Database.Audit.ListByActionsAsync(null, [], 1000, null, Ct)).Items.Select(e => e.Id).ToHashSet(); + Assert.True(entries.All(kept.Contains), "no audit entry was deleted"); + + // Saved in Settings › Logs, a retention becomes the schedule's age limit and turns it on, without a restart. + await SaveAuditRetentionAsync(admin, 30); + Assert.Equal(30, server.Options.AuditRetentionDays); + audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup); + Assert.Equal(((int?)30, true), (audit.Parameters.OlderThanDays, audit.Enabled)); + + // Without an environment variable the schedule stays editable; Reset goes back to the setting. + using (var edit = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}", new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(Steps: ["audit"], OlderThanDays: 60)), + ProtocolJson.Default.UpdateScheduleRequest)) + Assert.Equal((int?)60, (await edit.ReadAsync(ProtocolJson.Default.ScheduleDto)).Parameters.OlderThanDays); + using (var reset = await admin.PostAsync($"/api/v1/schedules/{audit.Id}/reset", null)) + Assert.Equal((int?)30, (await reset.ReadAsync(ProtocolJson.Default.ScheduleDto)).Parameters.OlderThanDays); + + // Back to 0: kept forever, the schedule off. + await SaveAuditRetentionAsync(admin, 0); + audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup); + Assert.Equal(((int?)0, false), (audit.Parameters.OlderThanDays, audit.Enabled)); + } + + /// Saves Settings › Logs › Keep audit (days) as the admin panel does. + private static async Task SaveAuditRetentionAsync(HttpClient admin, int days) + { + using var read = await admin.GetAsync("/api/v1/server/settings"); + var settings = await read.ReadAsync(ProtocolJson.Default.ServerSettingsDto); + // The test server listens on ports the OS chose, which the settings refuse: real ones are sent with the edit. + using var saved = await admin.PutAsJsonAsync("/api/v1/server/settings", + settings with { HttpPort = 18080, HttpsPort = 18443, Logs = settings.Logs with { AuditRetentionDays = days } }, ProtocolJson.Default.ServerSettingsDto); + await saved.ExpectAsync(HttpStatusCode.OK); + } + [Test] public async Task RunNowQueuesTheJobsOnceAndListsThemAsRuns() { @@ -342,7 +396,7 @@ public sealed class ScheduleEndpointTests(TestContext context) Assert.True(store.Exists(id)); var scheduleId = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.UploadCleanup, Ct)).Id; - // Two days later its half-hourly run expires the upload and deletes its partial file. + // Two days later its run (every 6 hours, with catch-up) expires the upload and deletes its partial file. clock.Advance(TimeSpan.FromHours(49)); await server.Services.GetRequiredService().Scheduler.RunDueAsync(Ct); var until = DateTime.UtcNow + TimeSpan.FromSeconds(30); @@ -373,7 +427,7 @@ public sealed class ScheduleEndpointTests(TestContext context) await using (var first = await TestServer.StartAsync(context, Paths, ArchiveModule.Register)) { var seeded = Assert.NotNull(await first.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.AuditCleanup, Ct)); - Assert.Equal((int?)365, ScheduleMapping.Parameters(seeded).OlderThanDays); + Assert.Equal(((int?)0, false), (ScheduleMapping.Parameters(seeded).OlderThanDays, seeded.Enabled)); } // CHRONOS_AUDIT_RETENTION_DAYS=30 at the next start. @@ -417,7 +471,9 @@ public sealed class ScheduleEndpointTests(TestContext context) var options = ServerOptions.Load(new Dictionary { ["CHRONOS_DATA_PATH"] = data, ["CHRONOS_DB"] = "postgres", [ServerOptions.AuditRetentionVariable] = "0" }); Assert.Equal(0, options.AuditRetentionDays); Assert.Contains(nameof(ServerOptions.AuditRetentionDays), options.Locked); - Assert.Equal(365, new ServerOptions().AuditRetentionDays); + Assert.Equal(0, new ServerOptions().AuditRetentionDays); + Assert.Equal(3650, ServerOptions.Load(new Dictionary { ["CHRONOS_DATA_PATH"] = data, ["CHRONOS_DB"] = "postgres", [ServerOptions.AuditRetentionVariable] = "3650" }) + .AuditRetentionDays); foreach (var invalid in new[] { "-1", "3651", "a year" }) { Assert.Throws(() =>