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
@@ -29,11 +29,78 @@ public abstract class JobRepositoryTests(TestContext context) : RepositoryTest(c
|
||||
State = JobState.Failed,
|
||||
Started = TestData.Now.AddMinutes(1),
|
||||
Finished = TestData.Now.AddMinutes(2),
|
||||
ScheduleId = Guid.CreateVersion7(),
|
||||
};
|
||||
await db.Jobs.EnqueueAsync(job, Ct);
|
||||
var read = Assert.NotNull(await db.Jobs.GetAsync(job.Id, Ct));
|
||||
Assert.SequenceEqual(job.TargetIds, read.TargetIds);
|
||||
Assert.Equal(job with { TargetIds = read.TargetIds }, read);
|
||||
Assert.Null((await db.Jobs.GetAsync((await EnqueueAsync(db, TestData.Job())).Id, Ct))!.ScheduleId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task JobsOfAScheduleAreListedNewestFirst()
|
||||
{
|
||||
var db = await OpenChronosAsync();
|
||||
var schedule = Guid.CreateVersion7();
|
||||
var older = await EnqueueAsync(db, TestData.Job(created: TestData.Now.AddMinutes(-5)) with { ScheduleId = schedule });
|
||||
var newer = await EnqueueAsync(db, TestData.Job() with { ScheduleId = schedule });
|
||||
await EnqueueAsync(db, TestData.Job());
|
||||
Assert.SequenceEqual([newer.Id, older.Id], (await db.Jobs.ListByScheduleAsync(schedule, cancellationToken: Ct)).Select(j => j.Id));
|
||||
Assert.Empty(await db.Jobs.ListByScheduleAsync(Guid.CreateVersion7(), cancellationToken: Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task JobsOfAScheduleArePagedNewestFirst()
|
||||
{
|
||||
// The runs a schedule's row lists in the admin panel (owner review 2, R10).
|
||||
var db = await OpenChronosAsync();
|
||||
var schedule = Guid.CreateVersion7();
|
||||
var jobs = new List<Job>();
|
||||
for (var i = 0; i < 3; i++) jobs.Add(await EnqueueAsync(db, TestData.Job(created: TestData.Now.AddMinutes(i)) with { ScheduleId = schedule }));
|
||||
await EnqueueAsync(db, TestData.Job(created: TestData.Now.AddMinutes(5)));
|
||||
|
||||
var first = await db.Jobs.PageByScheduleAsync(schedule, 2, null, Ct);
|
||||
Assert.SequenceEqual([jobs[2].Id, jobs[1].Id], first.Items.Select(j => j.Id));
|
||||
var second = await db.Jobs.PageByScheduleAsync(schedule, 2, Assert.NotNull(first.NextCursor), Ct);
|
||||
Assert.SequenceEqual([jobs[0].Id], second.Items.Select(j => j.Id));
|
||||
Assert.Null(second.NextCursor);
|
||||
Assert.Empty((await db.Jobs.PageByScheduleAsync(Guid.CreateVersion7(), cancellationToken: Ct)).Items);
|
||||
// A cursor of another listing is refused.
|
||||
var other = await db.Jobs.ListAsync(null, 1, null, Ct);
|
||||
await Assert.ThrowsAsync<FormatException>(() => db.Jobs.PageByScheduleAsync(schedule, 2, Assert.NotNull(other.NextCursor), Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PendingJobsAreFoundByKindAndTarget()
|
||||
{
|
||||
// A schedule queues nothing while a job doing the same work waits, runs or is paused (owner review 2, R10).
|
||||
var db = await OpenChronosAsync();
|
||||
Guid archive = Guid.CreateVersion7(), a = Guid.CreateVersion7(), b = Guid.CreateVersion7(), c = Guid.CreateVersion7();
|
||||
await EnqueueAsync(db, TestData.Job(JobKind.Scan) with { TargetIds = [archive] });
|
||||
await EnqueueAsync(db, TestData.Job(JobKind.Thumbs) with { TargetIds = [a, b], State = JobState.Paused });
|
||||
await EnqueueAsync(db, TestData.Job(JobKind.Thumbs) with { TargetIds = [c], State = JobState.Done, Finished = TestData.Now });
|
||||
await EnqueueAsync(db, TestData.Job(JobKind.Verify) with { TargetIds = [archive], State = JobState.Failed, Finished = TestData.Now });
|
||||
|
||||
Assert.True(await db.Jobs.HasPendingAsync([JobKind.Scan, JobKind.Rebuild], [archive], Ct));
|
||||
Assert.False(await db.Jobs.HasPendingAsync([JobKind.Rebuild], [archive], Ct));
|
||||
Assert.False(await db.Jobs.HasPendingAsync([JobKind.Verify], [archive], Ct), "a failed job is not pending");
|
||||
Assert.True(await db.Jobs.HasPendingAsync([JobKind.Thumbs], [b], Ct), "the second of a job's targets");
|
||||
Assert.True(await db.Jobs.HasPendingAsync([JobKind.Thumbs], null, Ct));
|
||||
Assert.False(await db.Jobs.HasPendingAsync([JobKind.Thumbs], [c], Ct), "a done job is not pending");
|
||||
Assert.False(await db.Jobs.HasPendingAsync([JobKind.Scan], [], Ct));
|
||||
|
||||
var claimed = await db.Jobs.ClaimNextAsync("node", [JobKind.Scan], Ct);
|
||||
Assert.Equal(JobState.Running, claimed!.State);
|
||||
Assert.True(await db.Jobs.HasPendingAsync([JobKind.Scan], [archive], Ct), "a running job is pending");
|
||||
Assert.SequenceEqual(new[] { a, b }.Order(), (await db.Jobs.ListPendingTargetsAsync(JobKind.Thumbs, Ct)).Order());
|
||||
Assert.Empty(await db.Jobs.ListPendingTargetsAsync(JobKind.Verify, Ct));
|
||||
}
|
||||
|
||||
private async Task<Job> EnqueueAsync(ChronosDatabase db, Job job)
|
||||
{
|
||||
await db.Jobs.EnqueueAsync(job, Ct);
|
||||
return job;
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in new issue
Block a user