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
@@ -1,4 +1,3 @@
|
||||
using System.Diagnostics;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Jobs;
|
||||
@@ -16,22 +15,20 @@ namespace Chronos.Server.Jobs;
|
||||
/// running one, in the order of the priority queue of the settings (owner review 1). Render jobs run here only when the registered render
|
||||
/// handler accepts them (<see cref="ISelectiveJobHandler"/>: managed formats, and MP4 jobs no render node can take);
|
||||
/// render nodes claim the others (BRIEF §14.5, §14.7). On shutdown running jobs stay marked running and are requeued from their checkpoints at the next start.
|
||||
/// Progress goes out through the <see cref="Gate"/> render nodes share, with what each job does now (owner review 5, #65).
|
||||
/// </summary>
|
||||
public sealed class JobEngineHost : IHostedService
|
||||
{
|
||||
private static readonly long ProgressInterval = Stopwatch.Frequency / 4;
|
||||
|
||||
private readonly ChronosDatabase _db;
|
||||
private readonly EventHub _events;
|
||||
private readonly HashSet<JobKind> _kinds;
|
||||
private readonly Dictionary<Guid, long> _lastProgress = [];
|
||||
private readonly Lock _gate = new();
|
||||
|
||||
public JobEngineHost(ChronosDatabase db, IEnumerable<IJobHandler> handlers, IEnumerable<IJobHandlerProvider> providers, ServerOptions options,
|
||||
EventHub events)
|
||||
EventHub events, TimeProvider time)
|
||||
{
|
||||
_db = db;
|
||||
_events = events;
|
||||
Gate = new ProgressGate(time);
|
||||
// A render handler must be selective: a plain one would take the jobs that need a render node's encoder.
|
||||
var local = handlers.Concat(providers.SelectMany(p => p.CreateJobHandlers())).Where(h => h.Kind != JobKind.Render || h is ISelectiveJobHandler).ToList();
|
||||
_kinds = [.. local.Select(h => h.Kind)];
|
||||
@@ -51,6 +48,9 @@ public sealed class JobEngineHost : IHostedService
|
||||
|
||||
public JobEngine Engine { get; }
|
||||
|
||||
/// <summary>The pace of every job's progress events, the server's own jobs and render nodes' alike.</summary>
|
||||
public ProgressGate Gate { get; }
|
||||
|
||||
/// <summary>True when a job of <paramref name="kind"/> has somewhere to run: a local handler, or render nodes for renders.</summary>
|
||||
public bool CanRun(JobKind kind) => kind == JobKind.Render || _kinds.Contains(kind);
|
||||
|
||||
@@ -63,21 +63,14 @@ public sealed class JobEngineHost : IHostedService
|
||||
|
||||
private void OnJobChanged(Job job)
|
||||
{
|
||||
if (job.State != JobState.Running)
|
||||
{
|
||||
lock (_gate) _lastProgress.Remove(job.Id);
|
||||
}
|
||||
if (job.State != JobState.Running) Gate.Forget(job.Id);
|
||||
_events.Publish(new JobStateEvent(job.Id, JobWire.State(job.State), job.Error));
|
||||
}
|
||||
|
||||
private void OnProgress(JobProgressInfo progress)
|
||||
{
|
||||
var now = Stopwatch.GetTimestamp();
|
||||
lock (_gate)
|
||||
{
|
||||
if (_lastProgress.TryGetValue(progress.JobId, out var last) && now - last < ProgressInterval && progress.Done < progress.Total) return;
|
||||
_lastProgress[progress.JobId] = now;
|
||||
}
|
||||
_events.Publish(new JobProgressEvent(progress.JobId, progress.Done, progress.Total, progress.ItemsPerSecond, progress.Eta?.TotalSeconds));
|
||||
if (!Gate.Passes(progress.JobId, progress.Done, progress.Total, progress.Detail?.Step ?? JobStep.None)) return;
|
||||
_events.Publish(new JobProgressEvent(progress.JobId, progress.Done, progress.Total, progress.ItemsPerSecond, progress.Eta?.TotalSeconds,
|
||||
JobWire.Detail(progress.Detail)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user