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:
1 parent
ac121acf7c
commit
422f33d5f3
12 files changed
+232
-52
No files matched your search
@@ -156,6 +156,38 @@ public sealed class SchedulerTests(TestContext context)
|
||||
Assert.Equal(0, await after.RunDueAsync(Ct));
|
||||
}
|
||||
|
||||
/// <summary>The server fixes an age limit from its environment there: a run caught up at start must already use it.</summary>
|
||||
[Test]
|
||||
public async Task AnEditBeforeTheFirstPassAppliesToTheRunCaughtUpAtStart()
|
||||
{
|
||||
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("audit-cleanup", "Audit log clean-up", ScheduleActions.Cleanup, ScheduleRecurrence.Parse("daily:04:30"),
|
||||
new ScheduleParametersDto(OlderThanDays: 90, Steps: ["audit"])));
|
||||
await using (await StartAsync(fx.Db, engine, host, clock))
|
||||
{
|
||||
}
|
||||
// The host was off over the run of 04:30.
|
||||
clock.Advance(TimeSpan.FromDays(1));
|
||||
await using var scheduler = new Scheduler(fx.Db, engine, new SchedulerOptions { Time = clock, Tick = TimeSpan.FromHours(1) });
|
||||
var id = Guid.Empty;
|
||||
await scheduler.StartAsync(host, async ct =>
|
||||
{
|
||||
var row = (await fx.Db.Schedules.GetBySystemKeyAsync("audit-cleanup", ct))!;
|
||||
id = row.Id;
|
||||
Assert.Empty(await fx.Db.Jobs.ListByScheduleAsync(id, cancellationToken: ct));
|
||||
var edit = await scheduler.UpdateAsync(id, new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(OlderThanDays: 365, Steps: ["audit"])), ct);
|
||||
Assert.Null(edit.Problem);
|
||||
}, Ct);
|
||||
|
||||
var jobs = await fx.Db.Jobs.ListByScheduleAsync(id, cancellationToken: Ct);
|
||||
Assert.Count(1, jobs);
|
||||
using var parameters = System.Text.Json.JsonDocument.Parse(jobs[0].ParametersJson!);
|
||||
Assert.Equal(365, parameters.RootElement.GetProperty("olderThanDays").GetInt32());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DisabledSchedulesNeverRunAndGetANewNextRunWhenEnabled()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user