fix(server): show the audit clean-up's real age limit and lock it before the first pass

Settings › Logs › Keep audit showed ServerOptions.AuditRetentionDays, a second
copy of the audit clean-up schedule's age limit. Edits made on Jobs › Scheduled
never reached it, so the panel could say "kept forever" while entries were
being deleted every night. Saving 0 there then changed nothing, because the
endpoint only compared against the stale option value.

- GET and PUT /server/settings now report the schedule's limit in force (0
  while the schedule is off). Saving compares against that value. A value sent
  back unchanged leaves the server.json reset default and the env lock alone. A
  new value sets the schedule and becomes the reset default.
- ApplyAgeAsync also turns the schedule on when it already holds the days but
  is off.
- CHRONOS_AUDIT_RETENTION_DAYS is now applied before the scheduler's first
  pass, through a new Scheduler.StartAsync overload with a beforeFirstPass hook.
  Before, a missed 04:30 run was caught up at start with the stale days, which
  could delete entries the variable says to keep. While the variable fixes a
  limit above 0, turning the schedule off is a 409 setting_locked.
- Corrected the comments in SchedulerHost, ServerOptions, ServerSettingsStore,
  LogSettingsDto, the header of settings.js and ARCHITECTURE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 490ed286e9f32745174b13b1963d6ec91955196b)
This commit is contained in:
Alby96 committed 2026-10-27 09:56:46 +01:00
1 parent ac121acf7c
commit 422f33d5f3
12 files changed
+232 -52

No files matched your search

+9 -1
View File
@@ -90,13 +90,21 @@ public sealed class Scheduler : IAsyncDisposable
/// Seeds <paramref name="host"/>'s system schedules, settles the runs missed while the host was off (see the type's
/// remarks) and starts the loop. The first pass runs before this returns.
/// </summary>
public async Task StartAsync(IScheduleHost host, CancellationToken cancellationToken = default)
public Task StartAsync(IScheduleHost host, CancellationToken cancellationToken = default) => StartAsync(host, null, cancellationToken);
/// <summary>
/// <see cref="StartAsync(IScheduleHost, CancellationToken)"/>, calling <paramref name="beforeFirstPass"/> once the system
/// schedules are seeded and edits are possible, before the first pass: what it changes (a value an environment variable
/// fixes) applies to the runs caught up at start too.
/// </summary>
public async Task StartAsync(IScheduleHost host, Func<CancellationToken, Task>? beforeFirstPass, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(host);
if (Host is not null) throw new InvalidOperationException("The scheduler has started already.");
var added = await _db.Schedules.EnsureSystemAsync(host.SystemSchedules, Now(), cancellationToken).ConfigureAwait(false);
if (added > 0) Log.Info("schedules", $"Added {added} system schedule(s)");
if (Interlocked.CompareExchange(ref _host, host, null) is not null) throw new InvalidOperationException("The scheduler has started already.");
if (beforeFirstPass is not null) await beforeFirstPass(cancellationToken).ConfigureAwait(false);
try
{
await RunDueAsync(cancellationToken).ConfigureAwait(false);