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:
Alby96andClaude Opus 5.5 committed 2026-11-15 13:02:59 +01:00
1 parent 58ed737310
commit ee9505df22
20 files changed
+968 -63

No files matched your search

+13 -6
View File
@@ -22,10 +22,16 @@ public sealed record JobEngineOptions
public TimeSpan CheckpointInterval { get; init; } = TimeSpan.FromSeconds(5);
/// <summary>
/// The shortest time between two publishes of one job's progress (<see cref="JobEngine.Progress"/>): twice a second. A new
/// step, a count that completes and the run's first report go out at once (<see cref="JobContext"/>).
/// </summary>
public TimeSpan ProgressInterval { get; init; } = TimeSpan.FromMilliseconds(500);
/// <summary>Fallback poll for jobs enqueued by other processes; also how often the priority queue is reviewed.</summary>
public TimeSpan PollInterval { get; init; } = TimeSpan.FromSeconds(3);
/// <summary>Clock of the throughput windows and the checkpoint interval (tests pass their own).</summary>
/// <summary>Clock of the throughput windows, the progress interval and the checkpoint interval (tests pass their own).</summary>
public TimeProvider Time { get; init; } = TimeProvider.System;
/// <summary>The priority queue as the settings have it now, asked at every claim and review; null: off (<see cref="JobPriorityQueue"/>).</summary>
@@ -77,7 +83,7 @@ public sealed class JobEngine : IAsyncDisposable
/// <summary>A job changed state (queued, running, done, failed, cancelled, paused).</summary>
public event Action<Job>? JobChanged;
/// <summary>Progress of a running job (high frequency; throttle in the UI).</summary>
/// <summary>Progress of a running job, at most once per <see cref="JobEngineOptions.ProgressInterval"/> per job but for new steps and completed counts.</summary>
public event Action<JobProgressInfo>? Progress;
public IReadOnlyCollection<Guid> RunningJobIds => [.. _running.Keys];
@@ -202,7 +208,8 @@ public sealed class JobEngine : IAsyncDisposable
try
{
var (rate, eta) = context.Rate();
Progress?.Invoke(new JobProgressInfo(context.Job.Id, context.Job.Kind, context.Job.TargetLabel, context.Done, context.Total, rate, eta, context.Message));
Progress?.Invoke(new JobProgressInfo(context.Job.Id, context.Job.Kind, context.Job.TargetLabel, context.Done, context.Total, rate, eta, context.Message,
context.Detail));
}
catch (Exception ex)
{
@@ -211,7 +218,7 @@ public sealed class JobEngine : IAsyncDisposable
}
/// <summary>
/// Saves progress, checkpoint and log tail; false when the job no longer runs here (cancelled or paused elsewhere).
/// Saves progress, its detail, checkpoint and log tail; false when the job no longer runs here (cancelled or paused elsewhere).
/// Saving is best effort and never throws: a failure is logged and the job goes on, so its final state is always written.
/// </summary>
internal async Task<bool> PersistAsync(JobContext context)
@@ -219,8 +226,8 @@ public sealed class JobEngine : IAsyncDisposable
try
{
var (rate, eta) = context.Rate();
return await _db.Jobs.UpdateProgressAsync(context.Job.Id, context.Done, context.Total, rate, eta, context.Checkpoint, context.LogTail, CancellationToken.None)
.ConfigureAwait(false);
return await _db.Jobs.UpdateProgressAsync(context.Job.Id, context.Done, context.Total, rate, eta, context.Checkpoint, context.LogTail, context.Detail,
CancellationToken.None).ConfigureAwait(false);
}
catch (DatabaseException ex) when (ex.IsTransient)
{