feat(app): Jobs › Scheduled and the desktop scheduler
Owner review 2, R10 on the desktop: every timer that queued work out of sight is now a visible, editable schedule of this PC. - DesktopScheduleHost implements IScheduleHost: the PC's time zone, the archive at Settings › Archive's folder (refreshed from archive.json, none while it is offline), and three system schedules: archive-scan (every:<ScanIntervalMinutes>m, seeded once from the old setting, no catch-up), index-backup (every day with catch-up, replacing DatabaseBackups.RunDailyAsync) and housekeeping (daily 04:00 with catch-up: job history 90 days and the new cache-trim step). - AppServices starts the Scheduler after the engine, once the archive was reopened; an unplugged archive is looked for every minute and the scheduler woken when it is back. The rescan loop and the daily backup loop are gone; ApplyJobSettings wakes the scheduler. - CacheStore.Trim brings the cache to Settings › Storage › Cache limit, oldest files first, skipping files in use and the proxies, render-node and server-import folders; CacheTrimStep runs it as a clean-up step. - Jobs gets a Queue | Scheduled segmented control. Scheduled lists the schedules (switch, name, action, when, next run, last result) with Run now, Edit, Reset (system) or Delete (user's, confirmed), the selected schedule's last runs with Show in queue, and an in-window editor that checks every field with the scheduler's limits. Jobs a schedule queued carry a "Scheduled" pill; the history line follows the housekeeping's job-history days. - JobNotices: a scheduled background run raises a toast only when it fails (upkeep stays silent). - Settings › Archive › Rescan every is removed; ScanIntervalMinutes stays only as the seed. Strings in en and it; the others are retranslated. - The capture shows jobs-scheduled and jobs-schedule-editor on a stopped scheduler clock with sample schedules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit e25d812feb3f417cb9251c748c29e8035fd9b03c)
This commit is contained in:
1 parent
75daab7275
commit
bc786c12c4
108 files changed
+3724
-490
No files matched your search
@@ -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)
|
||||
{
|
||||
@@ -636,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,
|
||||
@@ -671,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),
|
||||
|
||||
Reference in new issue
Block a user