feat(jobs): progress detail contract and a 2/s publish throttle
Mass passes need to say what they do now (photo x of y, sequence n of m) without slowing down. This adds the contract and the engine side; handlers and displays follow in their own parcels. - Core: JobDetail (step, item, item x of y, part n of m with unit), JobStep and JobPartUnit appended-only and stored by kebab name; Job.Detail. - Protocol: JobDetailDto, appended as JobDto.Detail, JobProgressEvent.Detail and NodeProgress.Detail, so older peers ignore it and newer ones fall back. - Data: JobContext keeps a detail across reports (ReportAsync with a detail, ReportItemAsync without allocating, CheckpointAsync with a detail) and publishes at most once per ProgressInterval (500 ms on the engine's TimeProvider), at once for the first report, a new step or a completed count; a dropped report costs no allocation or lock, and the persist that falls due publishes what it saves. Persist stays at most every 5 s. JobWire maps steps, units and details; an unknown name reads as none. - Migration 0011 adds jobs.progress_detail (nullable JSON text); an unreadable cell reads as no detail. Lists return it. - Server: ProgressGate (500 ms per job, step-change and completion bypass) shared by the engine host and render nodes; node details are stored and broadcast, an older node without one still works. Refs #65 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58ed737310
commit
ee9505df22
20 files changed
+968
-63
No files matched your search
@@ -30,12 +30,52 @@ public abstract class JobRepositoryTests(TestContext context) : RepositoryTest(c
|
||||
Started = TestData.Now.AddMinutes(1),
|
||||
Finished = TestData.Now.AddMinutes(2),
|
||||
ScheduleId = Guid.CreateVersion7(),
|
||||
Detail = new JobDetail(JobStep.Encode, "Harbour sunset", 5, 10, 1, 2, JobPartUnit.Render),
|
||||
};
|
||||
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);
|
||||
var plain = (await db.Jobs.GetAsync((await EnqueueAsync(db, TestData.Job())).Id, Ct))!;
|
||||
Assert.Null(plain.ScheduleId);
|
||||
Assert.Null(plain.Detail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheProgressDetailIsSavedWithTheProgressAndListedWithTheJob()
|
||||
{
|
||||
var db = await OpenChronosAsync();
|
||||
var job = TestData.Job(JobKind.Verify);
|
||||
await db.Jobs.EnqueueAsync(job, Ct);
|
||||
await db.Jobs.ClaimNextAsync("w", cancellationToken: Ct);
|
||||
var detail = new JobDetail(JobStep.Verify, "Harbour sunset · 2024", 812, 2400, 3, 41, JobPartUnit.Sequence);
|
||||
Assert.True(await db.Jobs.UpdateProgressAsync(job.Id, 4, 10, null, null, "cursor:4", null, detail, Ct));
|
||||
Assert.Equal(detail, (await db.Jobs.GetAsync(job.Id, Ct))!.Detail);
|
||||
// Lists read it too: a paused job tells where it stopped.
|
||||
Assert.SequenceEqual([detail], (await db.Jobs.ListBriefAsync(JobState.Running, null, cancellationToken: Ct)).Items.Select(j => j.Detail));
|
||||
|
||||
// Without a detail the column is cleared; a node's progress keeps or replaces it.
|
||||
Assert.True(await db.Jobs.UpdateProgressAsync(job.Id, 5, 10, null, null, "cursor:5", null, Ct));
|
||||
Assert.Null((await db.Jobs.GetAsync(job.Id, Ct))!.Detail);
|
||||
var node = new JobDetail(JobStep.Encode, null, 120, 3600);
|
||||
Assert.True(await db.Jobs.UpdateNodeProgressAsync(job.Id, "w", 6, 10, null, null, null, node, Ct));
|
||||
Assert.True(await db.Jobs.UpdateNodeProgressAsync(job.Id, "w", 7, 10, null, null, "line", Ct));
|
||||
Assert.Equal(node, (await db.Jobs.GetAsync(job.Id, Ct))!.Detail);
|
||||
Assert.True(await db.Jobs.UpdateNodeProgressAsync(job.Id, "w", 8, 10, null, null, null, null, Ct));
|
||||
Assert.Null((await db.Jobs.GetAsync(job.Id, Ct))!.Detail);
|
||||
|
||||
// A cell this build cannot read is no detail, never an error.
|
||||
foreach (var unreadable in new[] { "not json", "42", "[]", "{\"step\": 7}" })
|
||||
{
|
||||
await using (var session = await db.Database.OpenAsync(Ct))
|
||||
await session.ExecuteAsync("UPDATE jobs SET progress_detail = $1 WHERE id = $2", [unreadable, job.Id], Ct);
|
||||
Assert.Null((await db.Jobs.GetAsync(job.Id, Ct))!.Detail);
|
||||
}
|
||||
// One of a newer build: its step and unit read as none, the counts stay.
|
||||
await using (var session = await db.Database.OpenAsync(Ct))
|
||||
await session.ExecuteAsync("UPDATE jobs SET progress_detail = $1 WHERE id = $2",
|
||||
["""{"step":"teleport","itemDone":3,"itemTotal":9,"part":2,"parts":4,"partUnit":"galaxy","future":true}""", job.Id], Ct);
|
||||
Assert.Equal(new JobDetail(JobStep.None, null, 3, 9, 2, 4), (await db.Jobs.GetAsync(job.Id, Ct))!.Detail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in new issue
Block a user