Files
Chronos/src/Chronos.App/Editor/SequenceJobs.cs
T
Alby96andClaude Opus 5.5 59e7aca006 feat(workspace): render a project on this PC from its originals
A workspace project that holds its originals now renders locally
(JobKind.WorkspaceRender), so the full-resolution render no longer
waits on the home. This holds also when the home is a server.

- The handler reads its inputs under the project's lease. It refuses
  proxies-only media, and it refuses frames without an original,
  saying how many lack one. It renders into exports/ with unique
  names and a resumable checkpoint.
- Each output gets a ledger entry: SHA-256, the render id from
  RenderJobHandler.RenderId, and the version, recorded only when
  versions/ holds it and its hash verifies.
- After rendering, the handler queues a WorkspaceSend follow-up for
  the outputs it recorded. A cancel leaves no partial file.
- The editor routes Originals media to the local engine even for a
  server home, and lists those jobs beside the server's. It treats
  WorkspaceRender like Render for the toast and the reload, says
  "Sent home" when a send ends, and shows unsent ledger renders as
  "Not sent".
- Version on render saves a changed project as a version noted
  "Render" before it renders, and sends it with Sync automatically.
  With the setting off, the render behaves as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 16:03:05 +01:00

56 lines
2.7 KiB
C#

using Chronos.Core.Model;
namespace Chronos.App.Editor;
/// <summary>
/// The analyses and renders of the open sequence that wait, run or are paused, as the source reports them (BRIEF §12.3
/// "while a job runs on this sequence, settings are disabled", §11.5): the editor's busy lock, whether Analyse would
/// queue a second analysis, and the server job the header of a server sequence shows. Call from one thread.
/// </summary>
public sealed class SequenceJobs(Guid sequenceId)
{
private readonly Dictionary<Guid, Job> _active = [];
/// <summary>An analysis or render runs: settings wait (a local render's send home does not hold them).</summary>
public bool IsBusy => _active.Values.Any(j => j.State == JobState.Running && j.Kind != JobKind.WorkspaceSend);
/// <summary>A deep analysis waits, runs or is paused.</summary>
public bool IsAnalysing => _active.Values.Any(j => j.Kind == JobKind.DeepAnalyse);
/// <summary>The job to show: one running, else one paused, else the oldest waiting; null when there is none.</summary>
public Job? Shown => First(_active.Values);
/// <summary>The job of <paramref name="kind"/> to show, chosen as <see cref="Shown"/> is (the Edit path's steps).</summary>
public Job? Active(JobKind kind) => First(_active.Values.Where(j => j.Kind == kind));
/// <summary>An analysis or render of this sequence, a workspace project's render on this PC or its send home (phase 5c).</summary>
public bool Concerns(Job job)
{
ArgumentNullException.ThrowIfNull(job);
return job.TargetIds.Contains(sequenceId) && IsSequenceKind(job.Kind);
}
/// <summary>The kinds the editor follows.</summary>
public static bool IsSequenceKind(JobKind kind) =>
kind is JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render or JobKind.WorkspaceRender or JobKind.WorkspaceSend;
/// <summary>The job is one of those that wait, run or are paused.</summary>
public bool IsActive(Guid jobId) => _active.ContainsKey(jobId);
/// <summary>Takes in a job's new state.</summary>
/// <returns>Whether a job joined or left the active ones or changed state; progress alone does not count.</returns>
public bool Track(Job job)
{
if (!Concerns(job)) return false;
if (job.State is not (JobState.Queued or JobState.Running or JobState.Paused)) return _active.Remove(job.Id);
var changed = !_active.TryGetValue(job.Id, out var known) || known.State != job.State;
_active[job.Id] = job;
return changed;
}
private static Job? First(IEnumerable<Job> jobs) => jobs
.OrderBy(j => j.State switch { JobState.Running => 0, JobState.Paused => 1, _ => 2 })
.ThenBy(j => j.Started ?? j.Created)
.FirstOrDefault();
}