merge: or5 parcel p4

# Conflicts:
#	src/Chronos.App/Sections/ServerView.xaml
#	src/Chronos.App/Sections/ServerViewModel.cs
#	src/Chronos.Server/Jobs/JobEngineHost.cs
This commit is contained in:
Alby96 committed 2026-11-15 15:01:31 +01:00
commit e367f03c80
127 files changed
+6822 -1117

No files matched your search

+69 -8
View File
@@ -15,18 +15,21 @@ 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.
/// When Chronos Desktop shares its library (owner review 5, #67) the engine is the desktop's own: this host relays it while the
/// server runs, never starts, stops or disposes it, and the jobs API shows only the kinds a server runs (<see cref="Exposes"/>):
/// the desktop's workspace, sync and download jobs stay its own.
/// 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 readonly ChronosDatabase _db;
private readonly EventHub _events;
private readonly HashSet<JobKind> _kinds;
private readonly bool _ownsEngine = true;
private int _subscribed;
public JobEngineHost(ChronosDatabase db, IEnumerable<IJobHandler> handlers, IEnumerable<IJobHandlerProvider> providers, ServerOptions options,
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.
@@ -39,8 +42,21 @@ public sealed class JobEngineHost : IHostedService
Kinds = _kinds,
PriorityQueue = () => ServerSettingsStore.PriorityQueue(options),
});
Engine.JobChanged += OnJobChanged;
Engine.Progress += OnProgress;
Subscribe();
}
/// <summary>
/// Relays <paramref name="engine"/>, an engine Chronos Desktop runs (owner review 5, #67), from <see cref="StartAsync"/> to
/// <see cref="StopAsync"/>; the engine stays the desktop's.
/// </summary>
public JobEngineHost(JobEngine engine, EventHub events, TimeProvider time)
{
ArgumentNullException.ThrowIfNull(engine);
_events = events;
Gate = new ProgressGate(time);
_ownsEngine = false;
_kinds = [];
Engine = engine;
}
/// <summary>Node id stamped on jobs this server runs.</summary>
@@ -51,15 +67,60 @@ public sealed class JobEngineHost : IHostedService
/// <summary>The pace of every job's progress events, the server's own jobs and render nodes' alike.</summary>
public ProgressGate Gate { get; }
/// <summary>The engine is the one Chronos Desktop runs, which shares its library (owner review 5, #67).</summary>
public bool Hosted => !_ownsEngine;
/// <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);
public bool CanRun(JobKind kind) => kind == JobKind.Render || (_ownsEngine ? _kinds.Contains(kind) : Engine.CanRun(kind) && Exposes(kind));
public Task StartAsync(CancellationToken cancellationToken) => Engine.StartAsync(cancellationToken);
/// <summary>
/// Whether the jobs API lists, shows and acts on jobs of <paramref name="kind"/>: every kind on a server of its own; on a
/// shared desktop library only the kinds a server runs (<see cref="ServerSettingsStore.Kinds"/>), so a client never sees or
/// cancels the desktop's own workspace, sync and download jobs (owner review 5, #67).
/// </summary>
public bool Exposes(JobKind kind) => _ownsEngine || ServerSettingsStore.Kinds.Contains(kind);
public async Task StopAsync(CancellationToken cancellationToken) => await Engine.DisposeAsync();
public Task StartAsync(CancellationToken cancellationToken)
{
if (_ownsEngine) return Engine.StartAsync(cancellationToken);
Subscribe();
return Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
if (_ownsEngine)
{
await Engine.DisposeAsync();
return;
}
// The desktop's engine runs on: only this server stops following it.
if (Interlocked.Exchange(ref _subscribed, 0) == 1)
{
Engine.JobChanged -= OnJobChanged;
Engine.Progress -= OnProgress;
}
}
private void Subscribe()
{
if (Interlocked.Exchange(ref _subscribed, 1) == 1) return;
Engine.JobChanged += OnJobChanged;
Engine.Progress += OnProgress;
}
/// <summary>
/// A job's state changed outside the engine (render nodes, cancellation of node jobs): Chronos Desktop's Jobs section
/// follows these as it follows its engine's own changes while it shares its library (owner review 5, #67).
/// </summary>
public event Action<Job>? ChangedOutside;
/// <summary>Publishes a state change made outside the engine (render nodes, cancellation of node jobs).</summary>
public void Publish(Job job) => OnJobChanged(job);
public void Publish(Job job)
{
OnJobChanged(job);
ChangedOutside?.Invoke(job);
}
private void OnJobChanged(Job job)
{