fix: one audit retention, scans at start, live deep analysis and a 6-hour upload sweep
Settle what the R10 scheduler and R11 log packages left open when they were integrated (owner review 2, phase 2). - Audit retention has one source of truth, the audit-cleanup schedule's age limit. AuditRetentionDays defaults to 0 (the audit log is kept forever, so an upgrade deletes nothing; the schedule is seeded off) and accepts 0-3650, what a schedule's age limit takes. Saving Settings › Logs › Keep audit sets the schedule's limit (on with a limit, off at 0) without a restart; CHRONOS_AUDIT_RETENTION_DAYS locks it and Reset goes back to it. - Both hosts scan right after start again, as their polling did: the server after the scheduler starts, the desktop once the archive was reopened and again when an unplugged one is back. Scheduler.RunSystemNowAsync runs the archive-scan schedule when it is enabled and has not run since the start, and skips while its scan is pending. - Desktop scans follow Settings › Analysis › After a scan at every run: a scan schedule without its own deep parameter asks the host (IScheduleHost.DeepAnalysisAfterScan), the archive-scan schedule no longer freezes the setting, and the editor offers deep only for analyses, so the setting's tooltip stays true. - The server's upload clean-up runs every 6 hours instead of every 30 minutes, to keep the job history readable; idle uploads still expire after UploadRetentionHours. - The Unraid template and docker-compose leave CHRONOS_LOG_LEVEL empty or commented out, and say that setting it locks both log levels, so the admin panel can change them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bc786c12c4
commit
8d66be709c
21 files changed
+299
-53
No files matched your search
@@ -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"
|
||||
|
||||
@@ -41,13 +41,13 @@
|
||||
<Config Name="Server name" Target="CHRONOS_SERVER_NAME" Default="Chronos Server" Mode="" Description="Name shown to clients." Type="Variable" Display="advanced" Required="false" Mask="false">Chronos Server</Config>
|
||||
<Config Name="Parallelism" Target="CHRONOS_PARALLELISM" Default="" Mode="" Description="Jobs run one at a time: photos the running job processes at once (empty: half the cores, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Priority queue" Target="CHRONOS_PRIORITY_QUEUE" Default="" Mode="" Description="true: a job of a higher kind pauses the running one, which resumes afterwards (empty: set it in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Log level" Target="CHRONOS_LOG_LEVEL" Default="Information" Mode="" Description="Level of the log files and, unless Console log level is set, of the container's log: Trace, Debug, Information, Warning, Error, Critical or None." Type="Variable" Display="advanced" Required="false" Mask="false">Information</Config>
|
||||
<Config Name="Log level" Target="CHRONOS_LOG_LEVEL" Default="" Mode="" Description="Trace, Debug, Information, Warning, Error, Critical or None: sets and locks the level of the log files and, unless Console log level is set, of the container's log; the admin panel can then no longer change either (empty: Information, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Console log level" Target="CHRONOS_LOG_CONSOLE_LEVEL" Default="" Mode="" Description="Level of the container's log alone (empty: the Log level's)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Log retention" Target="CHRONOS_LOG_RETENTION_DAYS" Default="" Mode="" Description="Days the log files in /data/logs are kept (empty: 14, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Log file size" Target="CHRONOS_LOG_MAX_FILE_MB" Default="" Mode="" Description="MB at which a log file continues in a numbered one; 0: no limit (empty: 50, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Logs total size" Target="CHRONOS_LOG_MAX_TOTAL_MB" Default="" Mode="" Description="MB all log files may take, the oldest deleted beyond it; 0: no limit (empty: 1024, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Log rotation" Target="CHRONOS_LOG_ROTATION" Default="" Mode="" Description="daily or hourly: a new log file every day or every hour, UTC (empty: daily, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Audit retention" Target="CHRONOS_AUDIT_RETENTION_DAYS" Default="" Mode="" Description="Days audit entries are kept; 0: forever (empty: forever, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Audit retention" Target="CHRONOS_AUDIT_RETENTION_DAYS" Default="" Mode="" Description="Days the Audit log clean-up schedule keeps audit entries; 0: forever (empty: forever, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="Diagnostics log size" Target="CHRONOS_DIAGNOSTICS_LOG_MB" Default="" Mode="" Description="MB from the end of each log file in the diagnostics zip (empty: 4, changeable in the admin panel)." Type="Variable" Display="advanced" Required="false" Mask="false"/>
|
||||
<Config Name="PUID" Target="PUID" Default="99" Mode="" Description="User id that owns files." Type="Variable" Display="advanced" Required="true" Mask="false">99</Config>
|
||||
<Config Name="PGID" Target="PGID" Default="100" Mode="" Description="Group id that owns files." Type="Variable" Display="advanced" Required="true" Mask="false">100</Config>
|
||||
|
||||
@@ -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 |
|
||||
|
||||
|
||||
+1
-1
@@ -434,7 +434,7 @@
|
||||
<data name="Admin.Schedules.When.Tip" xml:space="preserve"><value>When it runs; times are in the server's time zone ({0})</value></data>
|
||||
<data name="Admin.Settings.About" xml:space="preserve"><value>About</value></data>
|
||||
<data name="Admin.Settings.AuditRetentionDays" xml:space="preserve"><value>Keep audit (days)</value></data>
|
||||
<data name="Admin.Settings.AuditRetentionDays.Tip" xml:space="preserve"><value>Days audit entries are kept before the housekeeping deletes them; 0: forever</value></data>
|
||||
<data name="Admin.Settings.AuditRetentionDays.Tip" xml:space="preserve"><value>Age limit of the Audit log clean-up schedule: older audit entries are deleted; 0: kept forever</value></data>
|
||||
<data name="Admin.Settings.ChunkSizeMib" xml:space="preserve"><value>Chunk size (MiB)</value></data>
|
||||
<data name="Admin.Settings.ChunkSizeMib.Tip" xml:space="preserve"><value>Size of each upload chunk; smaller chunks resume faster on poor links</value></data>
|
||||
<data name="Admin.Settings.ConsoleLogLevel" xml:space="preserve"><value>Console level</value></data>
|
||||
|
||||
@@ -337,7 +337,6 @@
|
||||
<data name="Tooltips.Jobs.Editor.CatchUp" xml:space="preserve"><value>A run missed while Chronos was closed happens once when it starts</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.Create" xml:space="preserve"><value>Create the schedule</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DayOfMonth" xml:space="preserve"><value>Day 1 to 28, which every month has</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DeepAfterScan" xml:space="preserve"><value>Sequences the scan indexes also get a deep analysis</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DeepAnalysis" xml:space="preserve"><value>A deep analysis of the sequences without one, instead of a light one</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DryRun" xml:space="preserve"><value>Lists what the maintenance would do without changing anything</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.Enabled" xml:space="preserve"><value>Off, the schedule never runs by itself</value></data>
|
||||
|
||||
@@ -433,7 +433,7 @@
|
||||
<data name="Admin.Schedules.When.Tip" xml:space="preserve"><value>Quando parte; gli orari sono nel fuso orario del server ({0})</value></data>
|
||||
<data name="Admin.Settings.About" xml:space="preserve"><value>Informazioni</value></data>
|
||||
<data name="Admin.Settings.AuditRetentionDays" xml:space="preserve"><value>Conserva controllo (giorni)</value></data>
|
||||
<data name="Admin.Settings.AuditRetentionDays.Tip" xml:space="preserve"><value>Giorni di conservazione delle voci di controllo prima che la manutenzione le elimini; 0: per sempre</value></data>
|
||||
<data name="Admin.Settings.AuditRetentionDays.Tip" xml:space="preserve"><value>Limite di età della pianificazione Pulizia registro controllo: le voci più vecchie vengono eliminate; 0: conservate per sempre</value></data>
|
||||
<data name="Admin.Settings.ChunkSizeMib" xml:space="preserve"><value>Dimensione blocco (MiB)</value></data>
|
||||
<data name="Admin.Settings.ChunkSizeMib.Tip" xml:space="preserve"><value>Dimensione di ogni blocco di caricamento; blocchi piccoli riprendono prima su linee lente</value></data>
|
||||
<data name="Admin.Settings.ConsoleLogLevel" xml:space="preserve"><value>Livello console</value></data>
|
||||
|
||||
@@ -336,7 +336,6 @@
|
||||
<data name="Tooltips.Jobs.Editor.CatchUp" xml:space="preserve"><value>Un'esecuzione persa mentre Chronos era chiuso avviene una volta all'avvio</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.Create" xml:space="preserve"><value>Crea la pianificazione</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DayOfMonth" xml:space="preserve"><value>Giorno da 1 a 28, che ogni mese ha</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DeepAfterScan" xml:space="preserve"><value>Le sequenze che la scansione indicizza ricevono anche un'analisi approfondita</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DeepAnalysis" xml:space="preserve"><value>Un'analisi approfondita delle sequenze che non ne hanno una, invece di una rapida</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.DryRun" xml:space="preserve"><value>Elenca cosa farebbe la manutenzione senza cambiare niente</value></data>
|
||||
<data name="Tooltips.Jobs.Editor.Enabled" xml:space="preserve"><value>Disattivata, la pianificazione non viene mai eseguita da sola</value></data>
|
||||
|
||||
@@ -288,10 +288,11 @@ public sealed class AppServices : IAsyncDisposable
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="ReopenInterval"/> 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 (<see cref="ScanNowAsync"/>). An archive whose archive.json is
|
||||
/// not there (an unplugged drive) is looked for every <see cref="ReopenInterval"/> 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.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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 <paramref name="since"/> (the first pass fired it) or its scan is still pending.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts <see cref="Scheduler"/> on this PC's engine: it seeds the system schedules and runs its first pass before
|
||||
/// <see cref="SchedulerReady"/> turns true. Without an engine, or when the schedules cannot be read, there is none.
|
||||
|
||||
@@ -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, <see cref="AppSettings.ScanIntervalMinutes"/>, 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
|
||||
/// (<see cref="DeepAnalysisAfterScan"/>), like the scans started by hand. Thread-safe: the scheduler calls it from its loop.
|
||||
/// </summary>
|
||||
public sealed class DesktopScheduleHost(AppSettings settings, Func<ChronosDatabase?> database, Func<ArchiveService?> archives) : IScheduleHost
|
||||
{
|
||||
@@ -43,7 +44,7 @@ public sealed class DesktopScheduleHost(AppSettings settings, Func<ChronosDataba
|
||||
public IReadOnlyList<SystemSchedule> 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, Func<ChronosDataba
|
||||
|
||||
/// <summary>The desktop runs every action its engine has a handler for.</summary>
|
||||
public string? Unavailable(string action) => null;
|
||||
|
||||
/// <summary>Settings › Analysis › After a scan, read at every run: a scheduled scan follows it as a scan started by hand does.</summary>
|
||||
public bool DeepAnalysisAfterScan => settings.DeepAnalysisAfterScan;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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;
|
||||
/// <summary>Analysis only: a scan's deep analysis follows Settings › Analysis › After a scan at every run.</summary>
|
||||
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
|
||||
{
|
||||
|
||||
@@ -29,6 +29,12 @@ public interface IScheduleHost
|
||||
/// <summary>The names of the clean-up steps this host's <see cref="JobKind.Cleanup"/> jobs run (normally those of <c>ArchiveService.CleanupSteps</c>).</summary>
|
||||
IReadOnlyList<string> CleanupSteps { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether a scan whose schedule leaves its <c>deep</c> 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.
|
||||
/// </summary>
|
||||
bool DeepAnalysisAfterScan { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Why this host does not run <paramref name="action"/> (a short code, e.g. <c>not-here</c>), or null when it may. Asked
|
||||
/// before the scheduler's own checks (<see cref="ScheduleUnavailable"/>), for the action list and at every run.
|
||||
|
||||
@@ -36,7 +36,10 @@ public sealed record ScheduleActionContext(ChronosDatabase Database, IScheduleHo
|
||||
/// </summary>
|
||||
public static class ScheduleActions
|
||||
{
|
||||
/// <summary>Incremental scan of the archive (<c>force</c>: a full one; <c>deep</c>: deep analysis of what it indexes).</summary>
|
||||
/// <summary>
|
||||
/// Incremental scan of the archive (<c>force</c>: a full one; <c>deep</c>: deep analysis of what it indexes; unset, as the
|
||||
/// host says at the run, <see cref="IScheduleHost.DeepAnalysisAfterScan"/>).
|
||||
/// </summary>
|
||||
public const string Scan = "scan";
|
||||
|
||||
/// <summary>Integrity check of the originals, the least recently verified first (<c>olderThanDays</c>, <c>percent</c>).</summary>
|
||||
@@ -96,7 +99,8 @@ public static class ScheduleActions
|
||||
/// <summary>The parameters a new schedule of <paramref name="action"/> starts with.</summary>
|
||||
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);
|
||||
|
||||
@@ -158,6 +158,19 @@ public sealed class Scheduler : IAsyncDisposable
|
||||
return new ScheduleRunDto(dto, fire.Outcome, fire.JobId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the system schedule <paramref name="systemKey"/> now (<see cref="RunNowAsync"/>, which skips while its work is
|
||||
/// pending) when it is enabled and has not run since <paramref name="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).
|
||||
/// </summary>
|
||||
public async Task<ScheduleRunDto?> 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);
|
||||
}
|
||||
|
||||
/// <summary>The schedules (system ones first), the actions with their availability here, the host's time zone and clean-up steps.</summary>
|
||||
public async Task<SchedulesDto> ListAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
@@ -74,8 +74,9 @@ public static class AdminEndpoints
|
||||
}
|
||||
|
||||
private static async Task<IResult> 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);
|
||||
}
|
||||
|
||||
@@ -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 <see cref="ServerLogging"/>
|
||||
/// (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
|
||||
/// <c>SchedulerHost.ApplyAuditRetentionAsync</c>).
|
||||
/// </summary>
|
||||
public sealed class ServerSettingsStore(ServerOptions options, ServerLogging logging)
|
||||
{
|
||||
|
||||
@@ -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 (<see cref="Scheduler.StartAsync"/>), applies the age limits that
|
||||
/// environment variables fix (<see cref="ServerScheduleHost.LockedAgeOf"/>), 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 (<see cref="ApplyAuditRetentionAsync"/>).
|
||||
/// </summary>
|
||||
public sealed class SchedulerHost : IHostedService
|
||||
{
|
||||
@@ -52,31 +54,43 @@ public sealed class SchedulerHost : IHostedService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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 (<see cref="ServerOptions.AuditRetentionDays"/>) 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.
|
||||
/// </summary>
|
||||
public Task ApplyAuditRetentionAsync(int days, CancellationToken cancellationToken = default) =>
|
||||
ApplyAgeAsync(ServerScheduleHost.AuditCleanup, days, "Settings › Logs", cancellationToken);
|
||||
|
||||
/// <summary>The age limits environment variables fix, put into their system schedules at every start.</summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the age limit of the system schedule <paramref name="systemKey"/> to <paramref name="days"/>, enabling it when it
|
||||
/// has a limit now and disabling it at 0; nothing when it already holds the value.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>The archive scan's run at start, unless the first pass already fired it or it is disabled.</summary>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ public sealed record LockedAge(string Setting, string Variable, int Days);
|
||||
/// What the server tells its <see cref="Scheduler"/> (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 <see cref="ServerOptions"/> once (the user's edits
|
||||
/// stay) and reset to the options as they are then.
|
||||
/// </summary>
|
||||
@@ -31,8 +31,11 @@ public sealed class ServerScheduleHost : IScheduleHost
|
||||
/// <summary>Minutes between two archive scans (the desktop's rhythm, as the polling had).</summary>
|
||||
public const int ScanMinutes = 10;
|
||||
|
||||
/// <summary>Minutes between two sweeps of abandoned uploads (as the upload maintenance had).</summary>
|
||||
public const int UploadSweepMinutes = 30;
|
||||
/// <summary>
|
||||
/// 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 <see cref="ServerOptions.UploadRetentionHours"/>, at most this much later.
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>The server runs every action it has a handler for; the scheduler finds the rest out itself.</summary>
|
||||
public string? Unavailable(string action) => null;
|
||||
|
||||
/// <summary>The server has no such setting: a scan schedule's own <c>deep</c> parameter decides, off when unset.</summary>
|
||||
public bool DeepAnalysisAfterScan => false;
|
||||
|
||||
/// <summary>
|
||||
/// The age limit of the system schedule <paramref name="systemKey"/> that an environment variable fixes
|
||||
/// (<c>CHRONOS_AUDIT_RETENTION_DAYS</c> for <see cref="AuditCleanup"/>); null when the schedule's own value applies.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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");
|
||||
}
|
||||
|
||||
/// <summary>Whether the scan job <paramref name="id"/> gives what it finds a deep analysis.</summary>
|
||||
private static async Task<bool> 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()
|
||||
{
|
||||
|
||||
@@ -41,6 +41,8 @@ internal sealed class TestScheduleHost(Archive? archive) : IScheduleHost
|
||||
|
||||
public IReadOnlyList<string> CleanupSteps { get; set; } = ["job-history", "audit", "trash-report"];
|
||||
|
||||
public bool DeepAnalysisAfterScan { get; set; }
|
||||
|
||||
public ValueTask<Archive?> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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<bool> 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<Guid> IngestAsync(ArchiveFixture fx, string key, int seed)
|
||||
{
|
||||
var staged = fx.Stage(ArchiveFixture.Start.AddMinutes(seed), seed);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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));
|
||||
}
|
||||
|
||||
/// <summary>Saves Settings › Logs › Keep audit (days) as the admin panel does.</summary>
|
||||
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<SchedulerHost>().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<string, string?> { ["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<string, string?> { ["CHRONOS_DATA_PATH"] = data, ["CHRONOS_DB"] = "postgres", [ServerOptions.AuditRetentionVariable] = "3650" })
|
||||
.AuditRetentionDays);
|
||||
foreach (var invalid in new[] { "-1", "3651", "a year" })
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
|
||||
Reference in new issue
Block a user