feat: owner review 2 phase 5b: the server as a project home (#17)
CI / Build and test (push) Successful in 9m58s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 14m8s
CI / PostgreSQL 16 integration (push) Successful in 8m55s
CI / PostgreSQL 17 integration (push) Successful in 8m50s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m22s
CI / Build and test (push) Successful in 9m58s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 14m8s
CI / PostgreSQL 16 integration (push) Successful in 8m55s
CI / PostgreSQL 17 integration (push) Successful in 8m50s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m22s
A Chronos Server keeps its sequences' projects, as a PC's archive does: Main and named projects with versions under /api/v1/sequences/{id}/projects, the projects capability and the projectChanged event. The desktop opens a server's sequences in the workspace (proxies downloaded, hash-checked, resumable) with Save version, Sync, conflicts, History, Restore and the project actions against the server. Renders can be of a project version. The admin panel lists a sequence's projects and versions. Strings in all 38 languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #17.
This commit is contained in:
1 parent
255e149087
commit
81c303f484
325 files changed
+11477
-516
No files matched your search
@@ -1,9 +1,12 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Server.Api;
|
||||
@@ -20,7 +23,9 @@ namespace Chronos.Server.Jobs;
|
||||
/// render jobs they can encode, report progress, and upload the output in resumable chunks that become a render of
|
||||
/// the sequence. A claimed job lists every frame with its flags (a node renders none missing, corrupt or excluded) and
|
||||
/// the proxies the server asks for (<see cref="ServerProxies"/>), which the node sends from the originals it fetched.
|
||||
/// A node that stops heart-beating loses its jobs to the queue (<see cref="RenderNodeMonitor"/>).
|
||||
/// A node that stops heart-beating loses its jobs to the queue (<see cref="RenderNodeMonitor"/>). A job of a project version
|
||||
/// (owner review 2, R8) gets that version's settings placed on the frames it lists, and its render records the project and
|
||||
/// the version.
|
||||
/// </summary>
|
||||
public sealed class RenderNodeService(
|
||||
ChronosDatabase db,
|
||||
@@ -90,14 +95,62 @@ public sealed class RenderNodeService(
|
||||
continue;
|
||||
}
|
||||
await TouchAsync(node, cancellationToken);
|
||||
if (await SettingsAsync(parameters, sequence, cancellationToken) is not { } settings)
|
||||
{
|
||||
await FinishAsync(node, job, JobState.Failed, Loc.L("Errors.Render.ProjectVersion"), cancellationToken);
|
||||
continue;
|
||||
}
|
||||
var spec = ServerProxies.Spec(archive.Current);
|
||||
return new ClaimedJob(Dto.Job(job), sequence.Id, parameters.SettingsJson ?? sequence.SettingsJson ?? "{}", parameters.PresetJson,
|
||||
parameters.UseProxies, await ServerProxies.FramesAsync(db, archive.Current, sequence, spec, cancellationToken), spec);
|
||||
// The frames the node renders and the photos a project version's positions are placed on, of one frames version.
|
||||
var snapshot = await SequenceEndpoints.SnapshotOfAsync(db, sequence.Id, async (on, row, ct) => (
|
||||
Frames: await ServerProxies.FramesAsync(on, archive.Current, row, spec, ct),
|
||||
Photos: settings.Portable ? HomePhotos.Of(await ProjectEndpoints.AllFramesAsync(on, row.Id, ct), await HomePhotos.AliasesAsync(on, row.Id, ct)) : null),
|
||||
cancellationToken);
|
||||
if (snapshot is not { } taken)
|
||||
{
|
||||
await FinishAsync(node, job, JobState.Failed, "The sequence no longer exists.", cancellationToken);
|
||||
continue;
|
||||
}
|
||||
var (frames, photos) = taken.Value;
|
||||
return new ClaimedJob(Dto.Job(job), sequence.Id, photos is null ? settings.Json : Placed(settings.Json, photos), parameters.PresetJson,
|
||||
parameters.UseProxies, frames, spec);
|
||||
}
|
||||
await TouchAsync(node, cancellationToken);
|
||||
return (ClaimedJob?)null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The settings a node renders: the job's own (a project version's portable form among them, whose positions are placed on
|
||||
/// the frames the node gets), else those of the project version the job names (owner review 2, R8), else the sequence's.
|
||||
/// Null when the job names a version that is not one of the sequence's projects'.
|
||||
/// </summary>
|
||||
private async Task<(string Json, bool Portable)?> SettingsAsync(RenderJobParameters parameters, Sequence sequence, CancellationToken cancellationToken)
|
||||
{
|
||||
if (parameters.SettingsJson is { } embedded) return (embedded, Waits(embedded));
|
||||
if (parameters.ProjectVersionId is not { } versionId) return (sequence.SettingsJson ?? "{}", false);
|
||||
return await db.Projects.GetVersionAsync(versionId, cancellationToken) is { } version
|
||||
&& await db.Projects.GetAsync(version.ProjectId, cancellationToken) is { } project && project.SequenceId == sequence.Id
|
||||
? (version.SettingsJson, Waits(version.SettingsJson))
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>Settings with positions that wait for their photos (a project version's portable form, settings synced from another copy).</summary>
|
||||
private static bool Waits(string settingsJson) => settingsJson.Contains("pendingFrames", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>The settings with their waiting positions placed on <paramref name="photos"/>, as the server's own render does; others as they are.</summary>
|
||||
private static string Placed(string settingsJson, FramePhotos photos)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ProjectContent.Place(settingsJson, photos);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Not a project: the node says so as it reads it.
|
||||
return settingsJson;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Outcome<bool>> ProgressAsync(Caller caller, Guid nodeId, Guid jobId, NodeProgress progress, CancellationToken cancellationToken)
|
||||
{
|
||||
if (await OwnedNodeAsync(caller, nodeId, cancellationToken) is not { } node) return Outcome<bool>.Fail(404, "not_found", "node");
|
||||
@@ -176,10 +229,15 @@ public sealed class RenderNodeService(
|
||||
if (await uploads.StageVerifiedAsync(upload, cancellationToken) is not { } staged) return Outcome<RenderDto>.Fail(422, "hash_mismatch");
|
||||
var output = JsonSerializer.Deserialize(upload.RenderJson, ProtocolJson.Default.RenderResultRequest)!;
|
||||
var sequence = await db.Sequences.GetAsync(job.TargetIds[0], cancellationToken);
|
||||
// The render records the project and the version its job rendered (owner review 2, R8).
|
||||
var rendered = JobEndpoints.ParseRender(job.ParametersJson);
|
||||
Render? render;
|
||||
try
|
||||
{
|
||||
render = sequence is null ? null : await renders.CommitAsync(sequence, staged, output, node.ClientName, cancellationToken);
|
||||
render = sequence is null
|
||||
? null
|
||||
: await renders.CommitAsync(sequence, staged, output, node.ClientName, Guid.CreateVersion7(), rendered?.ProjectId, rendered?.ProjectVersionId,
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException or FolderMovedException)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user