fix: address the owner review 5 review
Setup: a kept 1.0 Uploader no longer fixes the scope and folder, the Remove tooltip promises kept files only with a hashed log, and a single-program setup preselects it. The Uploader always downloads the setup. Sync links move to the server id at every sign-in while folders wait for jobs and open editors; jobs of a pending homes sort still find their projects. A shared library exposes only the shared archive's client-visible jobs and events, render nodes take only client renders, and the share counts as its own while starting. Progress: a new step waits a quarter interval and a trailing timer publishes the last state; the job bar tooltip carries the whole line; Recent maintenance and the Server jobs list pick up jobs that start while they are shown. Refs #64 #65 #66 #67 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
817956e719
commit
f30eb2904a
51 files changed
+895
-122
No files matched your search
@@ -5,6 +5,7 @@ using Chronos.Protocol;
|
||||
using Chronos.Server.Api;
|
||||
using Chronos.Server.Configuration;
|
||||
using Chronos.Server.Events;
|
||||
using Chronos.Server.Storage;
|
||||
|
||||
namespace Chronos.Server.Jobs;
|
||||
|
||||
@@ -16,8 +17,9 @@ namespace Chronos.Server.Jobs;
|
||||
/// 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.
|
||||
/// server runs, never starts, stops or disposes it, and the jobs API and the events show only the jobs of the kinds a server
|
||||
/// runs (<see cref="Exposes"/>) on the archive it serves and its sequences (<see cref="ServesAsync"/>): the desktop's
|
||||
/// workspace, sync and download jobs, and its jobs on other archives, 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
|
||||
@@ -25,6 +27,13 @@ public sealed class JobEngineHost : IHostedService
|
||||
private readonly EventHub _events;
|
||||
private readonly HashSet<JobKind> _kinds;
|
||||
private readonly bool _ownsEngine = true;
|
||||
private readonly ServerArchive? _archive;
|
||||
private readonly ChronosDatabase? _db;
|
||||
|
||||
/// <summary>Hosted: whether each job seen is the shared archive's (its targets never change), and the latest state of one still being looked up.</summary>
|
||||
private readonly Dictionary<Guid, bool> _served = [];
|
||||
private readonly Dictionary<Guid, Job> _deciding = [];
|
||||
private readonly Lock _decide = new();
|
||||
private int _subscribed;
|
||||
|
||||
public JobEngineHost(ChronosDatabase db, IEnumerable<IJobHandler> handlers, IEnumerable<IJobHandlerProvider> providers, ServerOptions options,
|
||||
@@ -47,15 +56,18 @@ public sealed class JobEngineHost : IHostedService
|
||||
|
||||
/// <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.
|
||||
/// <see cref="StopAsync"/>; the engine stays the desktop's. With <paramref name="archive"/> and <paramref name="db"/>, only
|
||||
/// that archive's jobs and its sequences' are relayed and listed (<see cref="ServesAsync"/>).
|
||||
/// </summary>
|
||||
public JobEngineHost(JobEngine engine, EventHub events, TimeProvider time)
|
||||
public JobEngineHost(JobEngine engine, EventHub events, TimeProvider time, ServerArchive? archive = null, ChronosDatabase? db = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(engine);
|
||||
_events = events;
|
||||
Gate = new ProgressGate(time);
|
||||
_ownsEngine = false;
|
||||
_kinds = [];
|
||||
_archive = archive;
|
||||
_db = db;
|
||||
Engine = engine;
|
||||
}
|
||||
|
||||
@@ -80,6 +92,33 @@ public sealed class JobEngineHost : IHostedService
|
||||
/// </summary>
|
||||
public bool Exposes(JobKind kind) => _ownsEngine || ServerSettingsStore.Kinds.Contains(kind);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the jobs API lists, shows and acts on <paramref name="job"/>, and its events go out: every job on a server of
|
||||
/// its own; on a shared desktop library a job of a kind it exposes (<see cref="Exposes"/>) whose target is the served
|
||||
/// archive or one of its sequences (owner review 5, #67), never the desktop's work on its other archives.
|
||||
/// </summary>
|
||||
public async ValueTask<bool> ServesAsync(Job job, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(job);
|
||||
if (_ownsEngine) return true;
|
||||
if (!Exposes(job.Kind)) return false;
|
||||
if (_archive is null || _db is null) return true;
|
||||
lock (_decide)
|
||||
{
|
||||
if (_served.TryGetValue(job.Id, out var known)) return known;
|
||||
}
|
||||
var served = await TargetsServedAsync(job, cancellationToken).ConfigureAwait(false);
|
||||
lock (_decide) _served[job.Id] = served;
|
||||
return served;
|
||||
}
|
||||
|
||||
/// <summary>The job's first target is the served archive or one of its sequences (a job without targets is the server's).</summary>
|
||||
private async Task<bool> TargetsServedAsync(Job job, CancellationToken cancellationToken)
|
||||
{
|
||||
if (job.TargetIds is not [var target, ..] || target == _archive!.Id) return true;
|
||||
return _archive.Owns(await _db!.Sequences.GetAsync(target, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_ownsEngine) return Engine.StartAsync(cancellationToken);
|
||||
@@ -125,11 +164,61 @@ public sealed class JobEngineHost : IHostedService
|
||||
private void OnJobChanged(Job job)
|
||||
{
|
||||
if (job.State != JobState.Running) Gate.Forget(job.Id);
|
||||
_events.Publish(new JobStateEvent(job.Id, JobWire.State(job.State), job.Error));
|
||||
// A shared desktop library tells its clients nothing of the desktop's own jobs (owner review 5, #67).
|
||||
if (!Exposes(job.Kind)) return;
|
||||
if (_ownsEngine || _archive is null || _db is null)
|
||||
{
|
||||
PublishState(job);
|
||||
return;
|
||||
}
|
||||
lock (_decide)
|
||||
{
|
||||
// Published under the lock, so the states of one job go out in order while its archive is looked up.
|
||||
if (_served.TryGetValue(job.Id, out var served))
|
||||
{
|
||||
if (served) PublishState(job);
|
||||
return;
|
||||
}
|
||||
var looking = _deciding.ContainsKey(job.Id);
|
||||
_deciding[job.Id] = job;
|
||||
if (looking) return;
|
||||
}
|
||||
_ = DecideAsync(job);
|
||||
}
|
||||
|
||||
/// <summary>Looks up whether the job is the shared archive's, then publishes the latest state it had meanwhile when it is.</summary>
|
||||
private async Task DecideAsync(Job job)
|
||||
{
|
||||
bool served;
|
||||
try
|
||||
{
|
||||
served = await TargetsServedAsync(job, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is DatabaseException or ObjectDisposedException or InvalidOperationException)
|
||||
{
|
||||
// Not known to be the archive's: its clients are told nothing of it.
|
||||
served = false;
|
||||
}
|
||||
lock (_decide)
|
||||
{
|
||||
_served[job.Id] = served;
|
||||
if (_deciding.Remove(job.Id, out var latest) && served) PublishState(latest);
|
||||
}
|
||||
}
|
||||
|
||||
private void PublishState(Job job) => _events.Publish(new JobStateEvent(job.Id, JobWire.State(job.State), job.Error));
|
||||
|
||||
private void OnProgress(JobProgressInfo progress)
|
||||
{
|
||||
if (!Exposes(progress.Kind)) return;
|
||||
if (!_ownsEngine && _archive is not null && _db is not null)
|
||||
{
|
||||
// Only a job known to be the shared archive's: its state, which comes first, decided it.
|
||||
lock (_decide)
|
||||
{
|
||||
if (!_served.TryGetValue(progress.JobId, out var served) || !served) return;
|
||||
}
|
||||
}
|
||||
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)));
|
||||
|
||||
@@ -5,8 +5,9 @@ namespace Chronos.Server.Jobs;
|
||||
/// <summary>
|
||||
/// How often a job's progress goes out on the event socket (owner review 5, #65): at most once per <see cref="Interval"/>
|
||||
/// per job, for the server's own jobs (<see cref="JobEngineHost"/>) and those render nodes run (<see cref="RenderNodeService"/>)
|
||||
/// alike. A job's first report, a new step and a count that completes always pass. A job that stops running is forgotten
|
||||
/// (<see cref="Forget"/>), so its next run starts afresh.
|
||||
/// alike. A job's first report and a count that completes always pass; a new step passes once a quarter of the interval went
|
||||
/// by, as the job engine publishes it, so a job that alternates steps does not flood the socket. A job that stops running is
|
||||
/// forgotten (<see cref="Forget"/>), so its next run starts afresh.
|
||||
/// </summary>
|
||||
public sealed class ProgressGate(TimeProvider time)
|
||||
{
|
||||
@@ -19,6 +20,9 @@ public sealed class ProgressGate(TimeProvider time)
|
||||
/// </summary>
|
||||
private static readonly TimeSpan Slack = TimeSpan.FromMilliseconds(50);
|
||||
|
||||
/// <summary>The shortest time before a new step passes: a quarter of <see cref="Interval"/>, as the job engine publishes one.</summary>
|
||||
private static readonly TimeSpan StepInterval = Interval / 4;
|
||||
|
||||
private readonly Dictionary<Guid, (long At, JobStep Step)> _last = [];
|
||||
private readonly Lock _gate = new();
|
||||
|
||||
@@ -28,8 +32,8 @@ public sealed class ProgressGate(TimeProvider time)
|
||||
var now = time.GetTimestamp();
|
||||
lock (_gate)
|
||||
{
|
||||
if (_last.TryGetValue(jobId, out var last) && last.Step == step && !(total > 0 && done >= total)
|
||||
&& time.GetElapsedTime(last.At, now) < Interval - Slack)
|
||||
if (_last.TryGetValue(jobId, out var last) && !(total > 0 && done >= total)
|
||||
&& time.GetElapsedTime(last.At, now) < (last.Step == step ? Interval : StepInterval) - Slack)
|
||||
return false;
|
||||
_last[jobId] = (now, step);
|
||||
return true;
|
||||
|
||||
@@ -87,6 +87,11 @@ public sealed class RenderNodeService(
|
||||
// A render the server's own engine started (it left a checkpoint) resumes there: only it knows that attempt's
|
||||
// leftovers and the batch entries it recorded.
|
||||
if (queued.Checkpoint is not null) continue;
|
||||
// A shared desktop library's queue is the desktop's (owner review 5, #67): a node takes the renders clients queued
|
||||
// through the API alone, never the desktop's own, which go where its user chose.
|
||||
if (jobs.Hosted && queued.CreatedBy is null) continue;
|
||||
// Only renders of the served archive's sequences: an index may hold other archives, whose frames the node cannot fetch.
|
||||
if (queued.TargetIds is [var target] && await db.Sequences.GetAsync(target, cancellationToken) is { } owner && !archive.Owns(owner)) continue;
|
||||
if (JobEndpoints.ParseRender(queued.ParametersJson) is not { } parameters || capabilities is null || !Renders(capabilities, parameters)) continue;
|
||||
// What the job renders now decides too (owner review 1, phase 4): the sequence's own settings may have changed
|
||||
// since it was queued, and a job of an older server carries no settings format.
|
||||
|
||||
Reference in new issue
Block a user