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

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:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-04 14:58:11 +01:00
1 parent 255e149087
commit 81c303f484
325 files changed
+11477 -516

No files matched your search

+19 -1
View File
@@ -14,13 +14,17 @@ namespace Chronos.Server.Storage;
/// thumbnails, and its job handlers (scan, rebuild, verify, import, thumbnails, proxies, maintenance, the duplicates and
/// orphans reports, index backups and clean-ups with the server's own steps, the <see cref="ICleanupStep"/>s in DI, Reorganize's
/// <c>move</c> jobs and the <c>convert</c> jobs, which tell connected clients of the sequences they change or make, and check
/// their space against the space volume's free bytes, <see cref="VolumeSpace.Report"/>); a scan
/// their space against the space volume's free bytes, <see cref="VolumeSpace.Report"/>); the projects of its sequences, every
/// change of them told to connected clients as <c>projectChanged</c> (owner review 2, R8); a scan
/// queues thumbnails and proxies of what it indexes, as an upload does. Decoding is managed only (BRIEF §4.2). Recurring
/// work (the periodic scan, the nightly backup of an SQLite index, clean-ups) is queued by the server's system schedules
/// (<see cref="Jobs.ServerScheduleHost"/>, owner review 2, R10).
/// </summary>
public static class ArchiveModule
{
/// <summary>The change a conversion's Replace tells about a sequence (<c>sequenceChanged</c>).</summary>
private const string ConvertedChange = "converted";
/// <summary>Name the server writes into the archive's lease files.</summary>
public static string Owner { get; } = "server@" + Environment.MachineName;
@@ -40,6 +44,18 @@ public static class ArchiveModule
{
if (await db.Sequences.GetAsync(id, ct) is { } sequence)
events.Publish(new SequenceChangedEvent(id, change, sequence.FramesVersion, sequence.SettingsVersion));
// A conversion may leave settings Main has not taken yet (owner review 2, R8).
if (change == ConvertedChange) sp.GetService<ProjectCatchUp>()?.Touch(id);
},
// Every change of a sequence's projects reaches connected clients (owner review 2, R8): a workspace with that
// project checked out knows its home moved, the admin panel lists the projects again. Main's head written into the
// sequence's settings is a settings change for the clients that read those (an older client, a desktop's sync).
ProjectsChanged = async (changed, ct) =>
{
foreach (var change in changed.Changes)
events.Publish(new ProjectChangedEvent(changed.SequenceId, change.ProjectId, change.Change, change.HeadNumber, change.HeadVersionId));
if (changed.SettingsChanged && await db.Sequences.GetAsync(changed.SequenceId, ct) is { } sequence)
events.Publish(new SequenceChangedEvent(sequence.Id, "settings", sequence.FramesVersion, sequence.SettingsVersion));
},
Decoder = DecoderFactory.CreateServer(),
// Where a conversion writes (owner review 2, R7): the tighter of what the panel shows as the archive's free space
@@ -48,6 +64,8 @@ public static class ArchiveModule
FreeSpace = volumes is null ? null : volumes.WritableFree,
Owner = Owner,
ImagesAfterScan = true,
// An earlier release's PATCH wrote settings into the index alone: they are never reverted to project.json's.
IndexSettingsMayLead = true,
Parallelism = () => options.Parallelism,
CleanupSteps = [.. sp.GetServices<ICleanupStep>()],
// Next to the index in the data folder, where the daily backups always went.
@@ -18,7 +18,8 @@ namespace Chronos.Server.Storage;
/// handler takes the jobs whose every output a managed encoder produces (AVI MJPEG, image sequences, GIF, APNG); MP4
/// jobs wait for render nodes until none can take them (<see cref="RenderNodeAvailability"/>), and then render here as
/// MJPEG in AVI with a line in the job log (BRIEF §14.7). Renders recorded and Auto values changed here reach connected
/// clients as <c>sequenceChanged</c> events (§14.3).
/// clients as <c>sequenceChanged</c> events (§14.3); Auto values changed become Main's next version (owner review 2, R8). A
/// render of a project version places that version's settings on the sequence's frames and records the project and the version.
/// </summary>
public static class ProcessingModule
{
@@ -32,7 +33,7 @@ public static class ProcessingModule
var options = sp.GetRequiredService<ServerOptions>();
return new ProcessingService(db, new ProcessingOptions
{
Archive = new ArchiveServiceOptions { Decoder = DecoderFactory.CreateServer(), Owner = ArchiveModule.Owner, Parallelism = () => options.Parallelism },
Archive = new ArchiveServiceOptions { Decoder = DecoderFactory.CreateServer(), Owner = ArchiveModule.Owner, IndexSettingsMayLead = true, Parallelism = () => options.Parallelism },
// Analyses and renders take the parallelism as it is when they start, and the one job that runs has the host's
// memory budget for its frame window, as on the desktop (owner review 1).
Tune = basis =>
@@ -48,6 +49,8 @@ public static class ProcessingModule
{
if (await db.Sequences.GetAsync(id, ct) is { } sequence)
events.Publish(new SequenceChangedEvent(id, change, sequence.FramesVersion, sequence.SettingsVersion));
// Auto values an analysis wrote into the settings become Main's next version now (owner review 2, R8).
if (change == ProcessingOptions.SettingsChange) sp.GetService<ProjectCatchUp>()?.Touch(id);
},
});
});
@@ -0,0 +1,89 @@
using System.Collections.Concurrent;
using System.Threading.Channels;
using Chronos.Core.Archiving;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Projects;
namespace Chronos.Server.Storage;
/// <summary>
/// Brings a sequence's projects in step soon after its settings were written outside the projects (owner review 2, R8): an
/// older client's or a desktop sync's <c>PATCH /sequences/{id}</c>, an analysis's Auto values, a conversion. Main takes them
/// as an external version at once (<see cref="ProjectService.CatchUpAsync"/>), and connected clients hear
/// <c>projectChanged</c> without waiting for the next project call, which would catch up all the same. Only a sequence that
/// has its Main project already: Main is made when the projects are first read, never for every sequence an analysis or a
/// sync touches. One sequence at a time in the background; a sequence asked for again while it waits is caught up once; one
/// another writer holds is tried again a few times, then left to that next call. Nothing happens without the archive engine
/// (a test host without it).
/// </summary>
public sealed class ProjectCatchUp(IServiceProvider services, ILogger<ProjectCatchUp> logger) : BackgroundService
{
/// <summary>The waits before each new try of a sequence another writer holds.</summary>
private static readonly TimeSpan[] Retries = [TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(2)];
private readonly Channel<(Guid Id, int Attempt)> _queue = Channel.CreateUnbounded<(Guid Id, int Attempt)>(new UnboundedChannelOptions { SingleReader = true });
private readonly ConcurrentDictionary<Guid, byte> _waiting = new();
private CancellationToken _stopping;
/// <summary>Catches the projects of <paramref name="sequenceId"/> up soon (at once when nothing waits).</summary>
public void Touch(Guid sequenceId) => Enqueue(sequenceId, 0);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_stopping = stoppingToken;
try
{
await foreach (var (id, attempt) in _queue.Reader.ReadAllAsync(stoppingToken))
{
_waiting.TryRemove(id, out _);
await CatchUpAsync(id, attempt, stoppingToken);
}
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
// The server stops: what waits is caught up by the next project call.
}
}
private void Enqueue(Guid id, int attempt)
{
if (_waiting.TryAdd(id, 0)) _queue.Writer.TryWrite((id, attempt));
}
private async Task CatchUpAsync(Guid id, int attempt, CancellationToken cancellationToken)
{
if (services.GetService<ArchiveService>() is not { } archives) return;
try
{
if (await services.GetRequiredService<ChronosDatabase>().Projects.GetMainAsync(id, cancellationToken) is null) return;
await archives.Projects.CatchUpAsync(id, cancellationToken);
}
catch (LeaseUnavailableException) when (attempt < Retries.Length)
{
_ = RetryLaterAsync(id, attempt);
}
catch (Exception ex) when (ex is ProjectException or ArchiveOfflineException or SequenceFolderMovedException or LeaseUnavailableException)
{
// The sequence is gone, its archive offline or its folder elsewhere, or it stayed busy: the next project call catches up.
logger.LogDebug("The projects of sequence {Sequence} are caught up later: {Reason}", id, ex.Message);
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
logger.LogWarning(ex, "The projects of sequence {Sequence} could not be caught up", id);
}
}
private async Task RetryLaterAsync(Guid id, int attempt)
{
try
{
await Task.Delay(Retries[attempt], _stopping);
Enqueue(id, attempt + 1);
}
catch (OperationCanceledException)
{
// Stopping.
}
}
}
+12 -1
View File
@@ -12,7 +12,7 @@ namespace Chronos.Server.Storage;
/// <param name="archives">The archive engine whose sequence lease the filing takes; one of its own when none is registered.</param>
public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeProvider time, ArchiveService? archives = null)
{
private readonly ArchiveService _archives = archives ?? new ArchiveService(db, new ArchiveServiceOptions { Owner = ArchiveModule.Owner });
private readonly ArchiveService _archives = archives ?? new ArchiveService(db, new ArchiveServiceOptions { Owner = ArchiveModule.Owner, IndexSettingsMayLead = true });
/// <summary>
/// Moves <paramref name="stagedFile"/> (on the archive volume) to <c>&lt;sequence folder&gt;/exports/</c>, never
@@ -31,6 +31,15 @@ public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeP
/// <exception cref="FolderMovedException">The sequence is not in the folder the index has.</exception>
public Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, Guid id,
CancellationToken cancellationToken) =>
CommitAsync(sequence, stagedFile, output, producedBy, id, null, null, cancellationToken);
/// <summary>
/// As above, recording the project and the version rendered (owner review 2, R8: a render node's output of a job that names
/// them); null for a render of the sequence's own settings.
/// </summary>
/// <exception cref="FolderMovedException">The sequence is not in the folder the index has.</exception>
public Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, Guid id, Guid? projectId,
Guid? projectVersionId, CancellationToken cancellationToken) =>
_archives.UnderLeaseAsync(sequence, async row =>
{
if (row is null || string.IsNullOrEmpty(row.Folder) || ArchivePathGuard.Resolve(archive.Root, row.Folder.TrimEnd('/') + "/exports") is not { } exports)
@@ -55,6 +64,8 @@ public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeP
Bytes = output.Size,
Created = time.GetUtcNow(),
ProducedBy = producedBy,
ProjectId = projectId,
ProjectVersionId = projectVersionId,
};
await db.Renders.InsertAsync(render, cancellationToken);
return (Render?)render;