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

- 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:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-27 11:19:26 +01:00
1 parent 1f089888e8
commit af9eeaab9b
349 files changed
+28341 -1304

No files matched your search

+67 -7
View File
@@ -24,6 +24,7 @@ using Chronos.Core.Video;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Jobs;
using Chronos.Data.Scheduling;
using Chronos.Data.Sync;
using Chronos.Protocol;
using Chronos.Protocol.Client;
@@ -33,8 +34,8 @@ namespace Chronos.App.DesignTime;
/// <summary>
/// Synthetic content for <c>--capture</c> screenshots and the screen smoke tests ONLY: a temporary SQLite index
/// with an archive of generated JPEGs (one sequence stores its thumbnail as an embedded preview inside a fake RAW
/// file), jobs in every state, a fake signed-in server with sequences to compare (one in conflict) and a fake
/// encoder inventory. Everything lives in the
/// file), jobs in every state, schedules (the system ones with runs, a weekly integrity check, a monthly report turned
/// off), a fake signed-in server with sequences to compare (one in conflict) and a fake encoder inventory. Everything lives in the
/// capture environment's temporary folder; nothing touches the network or the user's data.
/// </summary>
public sealed class SampleData
@@ -55,6 +56,8 @@ public sealed class SampleData
private ChronosDatabase? _db;
private Guid _sunrise;
private Guid _lakeComo;
private Guid _weeklyVerify = Guid.CreateVersion7();
private Guid? _scanSchedule;
private Permissions _permissions = RolePermissions.Default(UserRole.Editor);
private SampleData(AppServices services) => _services = services;
@@ -77,6 +80,8 @@ public sealed class SampleData
services.Devices = new SampleDeviceMonitor();
services.Sync.RemoteFactory = (_, _, _) => sample._remote;
services.Sync.EditorFactory = (_, _, _) => sample._remote;
// The schedules keep the sample's moment: nothing becomes due while the screenshots are taken.
services.SchedulerTime = new FixedTime(Now);
return sample;
}
@@ -109,7 +114,10 @@ public sealed class SampleData
await db.Sequences.SetTagsAsync(sequences[0].Sequence.Id, ["sunset", "harbour"]);
await db.Sequences.SetTagsAsync(sequences[9].Sequence.Id, ["holy grail"]);
foreach (var job in Jobs(sequences.Select(s => s.Sequence).ToList(), archive.Id)) await db.Jobs.EnqueueAsync(job);
_scanSchedule = (await db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.ArchiveScan))?.Id;
var jobs = Jobs(sequences.Select(s => s.Sequence).ToList(), archive.Id).ToList();
foreach (var job in jobs) await db.Jobs.EnqueueAsync(job);
await FillSchedulesAsync(db, jobs);
await FillServerAsync(db, sequences.Select(s => s.Sequence).ToList());
await SampleCards.InsertAsync(db, (SampleDeviceMonitor)_services.Devices, _services.Environment.DataDirectory);
await FillViewsAsync(db);
@@ -126,6 +134,53 @@ public sealed class SampleData
settings.FirstRunCompleted = true;
}
/// <summary>
/// Jobs › Scheduled (owner review 2, R10): the archive scan ran 4 minutes ago (its scan is in the history), the index
/// backup yesterday, the housekeeping never yet; a weekly integrity check the user made, whose run waits in the queue, and
/// a monthly orphans report turned off.
/// </summary>
private async Task FillSchedulesAsync(ChronosDatabase db, IReadOnlyList<Job> jobs)
{
var verify = jobs.First(j => j.ScheduleId == _weeklyVerify);
var weekly = ScheduleRecurrence.WeeklyAt([DayOfWeek.Sunday], new TimeOnly(2, 0));
var created = Now.AddDays(-40);
await db.Schedules.InsertAsync(new Schedule
{
Id = _weeklyVerify,
Name = "Weekly integrity check",
Action = ScheduleActions.Verify,
ParametersJson = ScheduleMapping.ParametersJson(ScheduleActions.Verify, new ScheduleParametersDto(OlderThanDays: 30, Percent: 25)),
Recurrence = weekly.Format(),
NextRun = weekly.Next(Now, TimeZoneInfo.Local),
LastRun = verify.Created,
LastJobId = verify.Id,
LastOutcome = ScheduleOutcome.Queued,
Created = created,
Updated = created,
});
var monthly = ScheduleRecurrence.MonthlyAt(1, new TimeOnly(5, 0));
await db.Schedules.InsertAsync(new Schedule
{
Id = Guid.CreateVersion7(),
Name = "Monthly orphans report",
Action = ScheduleActions.Orphans,
Recurrence = monthly.Format(),
Enabled = false,
Created = created.AddMinutes(5),
Updated = created.AddMinutes(5),
});
if (_scanSchedule is { } scan && jobs.FirstOrDefault(j => j.ScheduleId == scan) is { } scanned)
await db.Schedules.RecordOutcomeAsync(scan, scanned.Id, ScheduleOutcome.Queued, scanned.Created);
if (await db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.IndexBackup) is { } backup)
await db.Schedules.RecordOutcomeAsync(backup.Id, null, ScheduleOutcome.SkippedNothing, Now.AddDays(-1).AddHours(-2));
}
/// <summary>A clock stopped at one moment (the schedules of the capture).</summary>
private sealed class FixedTime(DateTimeOffset now) : TimeProvider
{
public override DateTimeOffset GetUtcNow() => now;
}
/// <summary>Two saved views of the Library ("Not analysed, largest" and one camera), BRIEF §12.2.</summary>
private static async Task FillViewsAsync(ChronosDatabase db)
{
@@ -185,7 +240,7 @@ public sealed class SampleData
{
var db = _db ?? throw new InvalidOperationException("FillAsync first.");
var service = _services.Sync.Service ?? throw new InvalidOperationException("The index is not open.");
// The history is kept whatever the date: the sample's finished jobs are dated from Now, not from today.
// The engine purges no history (the housekeeping schedule does): the sample's finished jobs, dated from Now, stay.
await using var engine = new JobEngine(db, service.CreateJobHandlers(_services.Sync),
new JobEngineOptions
{
@@ -193,7 +248,6 @@ public sealed class SampleData
WorkerId = "sample-proxies",
Kinds = [JobKind.Download],
PollInterval = TimeSpan.FromMilliseconds(50),
HistoryRetention = TimeSpan.FromDays(36_500),
});
await engine.StartAsync();
var job = await service.EnqueueDownloadAsync(engine, ServerAddress, _sunrise, "Sunrise over Superga", SyncDownloadMode.Proxies, null);
@@ -637,10 +691,11 @@ public sealed class SampleData
var here = _services.WorkerId;
Job Make(JobKind kind, Sequence? target, string label, JobState state, long done, long total, double? rate = null, TimeSpan? eta = null,
TimeSpan? startedAgo = null, TimeSpan? runFor = null, string? node = null, string? error = null, string? log = null,
JobPriority priority = JobPriority.Normal, TimeSpan? createdAgo = null) => new()
JobPriority priority = JobPriority.Normal, TimeSpan? createdAgo = null, Guid? schedule = null) => new()
{
Id = Guid.CreateVersion7(),
Kind = kind,
ScheduleId = schedule,
TargetIds = target is null ? [archiveId] : [target.Id],
TargetLabel = label,
State = state,
@@ -672,9 +727,14 @@ public sealed class SampleData
yield return Make(JobKind.Proxies, s[1], s[1].DisplayTitle, JobState.Paused, 915, 1_005, startedAgo: TimeSpan.FromMinutes(14),
priority: JobPriority.Background);
yield return Make(JobKind.Render, s[3], "Aurora, Tromsø → 1080p share H.264", JobState.Queued, 0, 0, createdAgo: TimeSpan.FromMinutes(12));
yield return Make(JobKind.Verify, null, "Archive · 2024", JobState.Queued, 0, 0, priority: JobPriority.Background, createdAgo: TimeSpan.FromMinutes(30));
// The weekly integrity check the user scheduled waits behind the user's jobs.
yield return Make(JobKind.Verify, null, "Archive · 2024", JobState.Queued, 0, 0, priority: JobPriority.Background, createdAgo: TimeSpan.FromMinutes(30),
schedule: _weeklyVerify);
yield return Make(JobKind.Verify, s[7], s[7].DisplayTitle, JobState.Failed, 640, 640, 900, startedAgo: TimeSpan.FromMinutes(25), runFor: TimeSpan.FromSeconds(43),
error: "2 files whose hash no longer matches the sidecar", log: "09:58:01 verify 640 files\n09:58:43 2 hash mismatches: 2025-08-02_0213.ARW, 2025-08-02_0214.ARW");
// The archive scan schedule's latest run.
yield return Make(JobKind.Scan, null, "ChronosArchive", JobState.Done, 412, 412, 640, startedAgo: TimeSpan.FromMinutes(4), runFor: TimeSpan.FromSeconds(1),
priority: JobPriority.Background, schedule: _scanSchedule);
yield return Make(JobKind.Render, s[5], "Milan skyline dusk → 4K HEVC", JobState.Done, 2_400, 2_400, 14.8, startedAgo: TimeSpan.FromMinutes(70),
runFor: new TimeSpan(0, 2, 41), node: "studio-pc");
yield return Make(JobKind.Import, s[0], "EOS R5 · card A → Archive · 4,812 photos", JobState.Done, 4_812, 4_812, 7.1, startedAgo: TimeSpan.FromMinutes(110),