feat: owner review 2 phase 2: scheduled jobs and log settings (#10)
CI / Build and test (push) Successful in 7m0s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 13m28s
CI / PostgreSQL 16 integration (push) Successful in 5m52s
CI / PostgreSQL 17 integration (push) Successful in 4m50s
CI / Docker image (push) Successful in 1m4s
Release / Server image (push) Successful in 1m35s
CI / Build and test (push) Successful in 7m0s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 13m28s
CI / PostgreSQL 16 integration (push) Successful in 5m52s
CI / PostgreSQL 17 integration (push) Successful in 4m50s
CI / Docker image (push) Successful in 1m4s
Release / Server image (push) Successful in 1m35s
- Jobs > Scheduled on the desktop and the admin panel. Every timer that queued work is now a visible system schedule: archive scan, upload clean-up, index backup, job-history and audit clean-ups, desktop housekeeping. New actions: verify, thumbnails, proxies, analysis, maintenance, backup, clean-ups, reports. - The scheduler: migration 0007, in-house recurrence, compare-and-set claim, catch-up, scan at start. - Log settings: levels, retention, size parts, total limit, daily or hourly rotation, audit retention, diagnostics share; the server writes Debug/Trace to its files again; logging never fails a job. Upgrade: CHRONOS_LOG_LEVEL set in an existing container locks both levels; migration 0007 is one-way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #10.
This commit is contained in:
1 parent
1f089888e8
commit
af9eeaab9b
349 files changed
+28341
-1304
No files matched your search
@@ -52,12 +52,16 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerOnSqliteBacksUpItsIndexOnStart()
|
||||
public async Task TheIndexBackupScheduleCopiesAnSqliteIndexIntoTheDataFolder()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var backups = Path.Combine(server.Options.DataPath, "backups");
|
||||
|
||||
// No copy yet, so the first one is made at once (BRIEF §6.2), named after the index it copies.
|
||||
// The nightly copy (BRIEF §6.2) is the index-backup system schedule's (owner review 2, R10), here run now.
|
||||
var schedule = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.IndexBackup, context.Cancellation));
|
||||
Assert.Equal("daily:03:00", schedule.Recurrence);
|
||||
var run = Assert.NotNull(await server.Services.GetRequiredService<SchedulerHost>().Scheduler.RunNowAsync(schedule.Id, null, context.Cancellation));
|
||||
Assert.Equal("queued", run.Outcome);
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
while (!Directory.Exists(backups) || Directory.GetFiles(backups, "*.db").Length == 0)
|
||||
{
|
||||
@@ -70,8 +74,34 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
Assert.Equal(server.Database.SchemaVersion, summary.SchemaVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The first start after the upgrade: the daily loop copied at start once the newest copy was a day old, so the index
|
||||
/// backup schedule is seeded due then (copied in the first pass) instead of waiting for 03:00.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PhotosAlreadyInTheArchiveAndAddedLaterAreIndexedByPollingWithThumbnailsAndProxies()
|
||||
public async Task TheFirstStartCopiesTheIndexWhenTheNewestCopyIsADayOld()
|
||||
{
|
||||
string? backups = null;
|
||||
await using var server = await TestServer.StartAsync(context, options =>
|
||||
{
|
||||
backups = Path.Combine(options.DataPath, Chronos.Data.DatabaseBackups.DirectoryName);
|
||||
Directory.CreateDirectory(backups);
|
||||
File.WriteAllText(Path.Combine(backups, $"chronos-{DateTime.UtcNow.AddDays(-7):yyyyMMdd-HHmmss}-000.db"), "copy");
|
||||
}, ArchiveModule.Register);
|
||||
|
||||
var schedule = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.IndexBackup, context.Cancellation));
|
||||
Assert.Equal("queued", schedule.LastOutcome);
|
||||
var path = Assert.NotNull(((Chronos.Data.Sqlite.SqliteDatabase)server.Database.Database).Path);
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(TestTiming.Budget(30));
|
||||
while (Chronos.Data.DatabaseBackups.List(backups!, path).Count < 2)
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, "no copy at the first start");
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PhotosAlreadyInTheArchiveAndAddedLaterAreIndexedByTheScanScheduleWithThumbnailsAndProxies()
|
||||
{
|
||||
var photo = Photo();
|
||||
// An adopted folder that already holds photos.
|
||||
@@ -87,10 +117,9 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
// The scan queues the thumbnails and proxies clients load from the server, as an upload does.
|
||||
await UntilImagesAsync(server, editor, archive.Id, "roof");
|
||||
|
||||
// Another writer adds a folder: the next poll queues a scan, but not while one is pending.
|
||||
// Another writer adds a folder: the next run of the scan schedule queues a scan, but not while one is pending.
|
||||
Directory.CreateDirectory(Path.Combine(server.Options.ArchivePath, "garden"));
|
||||
File.WriteAllBytes(Path.Combine(server.Options.ArchivePath, "garden", "IMG_0002.JPG"), Photo(seed: 3));
|
||||
var polling = server.Services.GetRequiredService<ArchivePolling>();
|
||||
var paused = new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
@@ -100,11 +129,13 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
};
|
||||
await server.Database.Jobs.EnqueueAsync(paused, context.Cancellation);
|
||||
Assert.Null(await polling.PollAsync(context.Cancellation));
|
||||
Assert.Equal("skipped-pending", (await RunScanAsync(server)).Outcome);
|
||||
await server.Services.GetRequiredService<JobEngineHost>().Engine.CancelAsync(paused.Id, context.Cancellation);
|
||||
|
||||
var scan = Assert.NotNull(await polling.PollAsync(context.Cancellation));
|
||||
Assert.Equal(JobPriority.Background, scan.Priority);
|
||||
var run = await RunScanAsync(server);
|
||||
Assert.Equal("queued", run.Outcome);
|
||||
var scan = Assert.NotNull(await server.Database.Jobs.GetAsync(run.JobId!.Value, context.Cancellation));
|
||||
Assert.Equal((JobKind.Scan, JobPriority.Background, (Guid?)run.Schedule.Id), (scan.Kind, scan.Priority, scan.ScheduleId));
|
||||
await UntilIndexedAsync(server, archive.Id, "garden");
|
||||
await UntilImagesAsync(server, editor, archive.Id, "garden");
|
||||
}
|
||||
@@ -141,8 +172,8 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
}
|
||||
Assert.Equal(1, Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).FrameCount);
|
||||
|
||||
// The next poll indexes it and queues the images: the new frame and the one it moved get theirs.
|
||||
Assert.NotNull(await server.Services.GetRequiredService<ArchivePolling>().PollAsync(context.Cancellation));
|
||||
// The scan schedule's next run indexes it and queues the images: the new frame and the one it moved get theirs.
|
||||
Assert.Equal("queued", (await RunScanAsync(server)).Outcome);
|
||||
await UntilScannedAsync(server);
|
||||
Assert.Equal(2, Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).FrameCount);
|
||||
await UntilImagesAsync(server, editor, archive.Id, "roof");
|
||||
@@ -182,11 +213,12 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var archive = server.Services.GetRequiredService<ServerArchive>();
|
||||
var polling = server.Services.GetRequiredService<ArchivePolling>();
|
||||
// Every run of a schedule reads the archive through its host, which takes archive.json's settings first.
|
||||
var schedules = server.Services.GetRequiredService<ServerScheduleHost>();
|
||||
// Nothing changed: the served archive (the one an administrator's edit put there) is not replaced by a row read again.
|
||||
var served = archive.Current;
|
||||
await polling.PollAsync(context.Cancellation);
|
||||
Assert.True(ReferenceEquals(served, archive.Current), "a poll that registered nothing keeps the served archive");
|
||||
await schedules.GetArchiveAsync(context.Cancellation);
|
||||
Assert.True(ReferenceEquals(served, archive.Current), "a refresh that registered nothing keeps the served archive");
|
||||
|
||||
// A desktop sharing the archive changed its folder template and proxy size in archive.json.
|
||||
var path = new ArchivePaths(archive.Root).ManifestPath;
|
||||
@@ -197,14 +229,14 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
ProxyPolicy = manifest.ProxyPolicy with { LongEdge = 2560 },
|
||||
});
|
||||
|
||||
await polling.PollAsync(context.Cancellation);
|
||||
Assert.Equal("{camera}/{date}", Assert.NotNull(await schedules.GetArchiveAsync(context.Cancellation)).FolderTemplate);
|
||||
|
||||
// Uploads (the index row) and the admin panel (the served archive) follow it.
|
||||
Assert.Equal(("{camera}/{date}", 2560), (archive.Current.FolderTemplate, archive.Current.ProxyLongEdge));
|
||||
var row = Assert.NotNull(await server.Database.Archives.GetAsync(archive.Id, context.Cancellation));
|
||||
Assert.Equal(("{camera}/{date}", 2560), (row.FolderTemplate, row.ProxyLongEdge));
|
||||
|
||||
// The admin panel opens before the next poll: its form, which saves every field, starts from the desktop's change.
|
||||
// The admin panel opens before the next run: its form, which saves every field, starts from the desktop's change.
|
||||
ManifestStore.WriteArchive(path, ManifestStore.ReadArchive(path) with { LayoutTemplates = manifest.LayoutTemplates with { Folder = "{year}/{camera}" } });
|
||||
var admin = await server.AdminAsync();
|
||||
using (var read = await admin.GetAsync("/api/v1/archive/settings"))
|
||||
@@ -275,6 +307,13 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Runs the archive-scan system schedule now, as its next run would.</summary>
|
||||
private static async Task<ScheduleRunDto> RunScanAsync(TestServer server)
|
||||
{
|
||||
var schedule = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.ArchiveScan));
|
||||
return Assert.NotNull(await server.Services.GetRequiredService<SchedulerHost>().Scheduler.RunNowAsync(schedule.Id, null));
|
||||
}
|
||||
|
||||
/// <summary>Waits for the scan queued at start to finish: its sequences are indexed before it ends.</summary>
|
||||
private static async Task UntilScannedAsync(TestServer server)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user