feat(jobs): every job handler reports a structured progress detail

The job list showed a bar and a free-text line that each handler worded
its own way. Each handler now reports its step, the item it is on, photo
x of y and sequence/folder/output/step n of m through the P2.1 JobContext
detail. Clients can word and lay that out themselves, and the 2/s
throttle keeps the cost low: counts within a step go through
ReportItemAsync, which allocates nothing.

- scan: List, then Index (folder n of m, photo x of y as an adopted or
  reconciled folder is read) or Check, then FollowUps
- verify, thumbs, proxies, deep analysis: photo x of y of sequence n of m;
  light analysis: sequence n of m; a thumbnail/proxy checkpoint carries
  the frame count it saves
- convert: Verify (resume), Convert photo x of y, Replace; reorganize:
  step n of m with the title; import: the file being copied, photo x of y
- maintenance: the step key, step n of 5, then Check; duplicates, orphans
  and backup run with no count; cleanup names step n of m; empty trash:
  entry n of m
- render (local, workspace, render node): Analyse, Encode (frames of the
  last output, output n of m in a batch), Verify; sync, video copy,
  workspace copy/send/move: Upload/Download/CopyProxy/CopyOriginal/
  CopyVideo/Reorganize with their items and counts

The detail carries keys and names only, never localized text. The
existing Message strings stay for clients that still show them.

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:38:05 +01:00
1 parent ee9505df22
commit 45e6911082
31 files changed
+759 -119

No files matched your search

@@ -11,6 +11,7 @@ using Chronos.Core.Project;
using Chronos.Core.Render;
using Chronos.Core.Video;
using Chronos.Data.Archiving;
using Chronos.Data.Jobs;
using Chronos.Protocol;
using Chronos.Protocol.Client;
@@ -261,6 +262,7 @@ public sealed class RenderNodeClient : IAsyncDisposable
};
IReadOnlyList<TargetOutcome> outcomes;
reporter.Step(JobStep.Encode, sequence.DisplayTitle);
await using (var render = new SequenceRender(input, project, null, _processing))
{
outcomes = await render.RenderAllAsync(
@@ -271,6 +273,8 @@ public sealed class RenderNodeClient : IAsyncDisposable
{
// Remarks first: completing the upload ends the job on the server.
foreach (var remark in SequenceRender.Remarks(result)) await reporter.LogAsync(remark).ConfigureAwait(false);
reporter.Step(JobStep.Upload, Path.GetFileName(result.OutputPath));
await reporter.ResendAsync().ConfigureAwait(false);
await UploadAsync(reporter.NodeId, claimed.Job.Id, t, result, cancellationToken).ConfigureAwait(false);
},
reporter.ReportAsync,
@@ -374,6 +378,8 @@ public sealed class RenderNodeClient : IAsyncDisposable
var fetched = claimed.Frames.Where(f => ((FrameFlags)f.Flags & NotFetched) == 0 && (Proxy(f) || !undecodable.Contains(f.Id))).ToList();
var done = 0;
var total = fetched.Count;
// The log line stays for servers that show no detail.
reporter.Step(JobStep.Download, null);
await reporter.ReportAsync(0, total, Loc.L("Export.Job.Downloading")).ConfigureAwait(false);
var downloads = fetched.GroupBy(f => Proxy(f) || f.Sha256.Length == 0 ? f.Id.ToString("N") : f.Sha256.ToLowerInvariant()).ToList();
await Parallel.ForEachAsync(downloads, new ParallelOptions { MaxDegreeOfParallelism = _options.Downloads, CancellationToken = cancellationToken },
@@ -575,11 +581,15 @@ public sealed class RenderNodeClient : IAsyncDisposable
};
/// <summary>
/// Progress of the job in flight to the server, at most every interval (and at the end). A refusal (409) means the
/// job was cancelled or given to another node: the job's token is cancelled.
/// Progress of the job in flight to the server, at most every interval (and at the end), with what the node does now
/// (<see cref="NodeProgress.Detail"/>: frames downloaded, encoded, the output uploaded; a server that shows no detail
/// ignores it). A refusal (409) means the job was cancelled or given to another node: the job's token is cancelled.
/// </summary>
private sealed class NodeReporter(ChronosClient client, Guid nodeId, Guid jobId, TimeSpan interval, CancellationTokenSource job)
{
private JobStep _step;
private string? _item;
private bool _stepChanged;
private readonly Stopwatch _clock = Stopwatch.StartNew();
private readonly SemaphoreSlim _gate = new(1, 1);
private TimeSpan _last = TimeSpan.MinValue;
@@ -589,9 +599,26 @@ public sealed class RenderNodeClient : IAsyncDisposable
public Guid NodeId => nodeId;
/// <summary>What the node does from now on; its next report is sent at once.</summary>
public void Step(JobStep step, string? item)
{
_gate.Wait(CancellationToken.None);
try
{
(_step, _item, _stepChanged) = (step, item, true);
}
finally
{
_gate.Release();
}
}
/// <summary>Progress, sent at most every interval; a stage message is sent when it changes.</summary>
public ValueTask ReportAsync(long done, long total, string? message) => SendAsync(done, total, message, remark: false);
/// <summary>The progress last reported, sent again with the step set since.</summary>
public ValueTask ResendAsync() => SendAsync(-1, -1, null, remark: false);
/// <summary>A line for the job's log on the server, sent with the progress last reported.</summary>
public ValueTask LogAsync(string line) => SendAsync(0, 0, line, remark: true);
@@ -607,13 +634,17 @@ public sealed class RenderNodeClient : IAsyncDisposable
}
else
{
if (done < 0) (done, total) = (_lastDone, _lastTotal);
var now = _clock.Elapsed;
var line = message is not null && message != _lastMessage ? message : null;
if (line is null && done < total && now - _last < interval) return;
if (line is null && !_stepChanged && done < total && now - _last < interval) return;
double? rate = _last == TimeSpan.MinValue || done < _lastDone ? null : (done - _lastDone) / double.Max((now - _last).TotalSeconds, 1e-3);
(_last, _lastDone, _lastTotal) = (now, done, total);
(_last, _lastDone, _lastTotal, _stepChanged) = (now, done, total, false);
if (line is not null) _lastMessage = line;
progress = new NodeProgress(done, total, rate, line);
var detail = _step == JobStep.None ? null
: new JobDetailDto(JobWire.Step(_step), _item is { Length: > JobDetail.MaxItemLength } item ? item[..JobDetail.MaxItemLength] : _item,
_step == JobStep.Upload ? 0 : done, _step == JobStep.Upload ? 0 : total);
progress = new NodeProgress(done, total, rate, line, detail);
}
await client.ReportNodeProgressAsync(nodeId, jobId, progress, job.Token).ConfigureAwait(false);
}