feat(processing): selective render claims, analysis follow-ups, per-sequence failures
- JobEngine: ISelectiveJobHandler lets a host decline jobs of a kind it runs; declined jobs stay queued for other claimers without holding up the rest. JobContext.EnqueueFollowUpAsync queues follow-up work on the same engine. - Server renders the jobs whose every output a managed encoder produces (ManagedRenderJobHandler); MP4 jobs stay for render nodes. Program.cs registers ProcessingModule next to ArchiveModule. Server renders ignore a client's export folder. - Light analysis is queued after imports and after scans that indexed new sequences, so the advisor's Auto values exist without user action. - Analysis jobs log a failing sequence and go on; the job then fails and a retry analyses only the failed ones. The advised frame rate follows the user's fit-to duration. - ProcessingJobs.RenderEach splits a batch into one job per preset for servers; render nodes say which batch presets they did not render, fetch each content once and stop on a changed certificate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
30 files changed
+572
-85
No files matched your search
@@ -0,0 +1,65 @@
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Tests.Archiving;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Data.Tests.Processing;
|
||||
|
||||
/// <summary>New sequences get their light analysis (and so their Auto values) without any user action (BRIEF §1.1).</summary>
|
||||
[Category("processing")]
|
||||
public sealed class AnalysisFollowUpTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task AnAdoptingScanQueuesLightAnalysisOfTheNewSequencesOnly()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
|
||||
await fx.StartEngineAsync(withArchive: true);
|
||||
|
||||
var scan = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive, full: true));
|
||||
await fx.WaitForAsync(scan.Id, JobState.Done);
|
||||
var light = Assert.NotNull(await SingleLightJobAsync(fx));
|
||||
await fx.WaitForAsync(light.Id, JobState.Done);
|
||||
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(light.TargetIds.Single(), fx.Ct))!;
|
||||
Assert.Equal("Roof", sequence.Folder);
|
||||
Assert.True(sequence.Status.HasFlag(SequenceStatus.AnalyzedLight), "analysed");
|
||||
Assert.True(ProjectSettings.FromJson(await File.ReadAllTextAsync(fx.Folder(sequence).ProjectPath, fx.Ct)).Timing.Mode.HasAdvice, "advised");
|
||||
|
||||
// Scans that find nothing new queue nothing more.
|
||||
foreach (var full in new[] { false, true })
|
||||
{
|
||||
var again = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive, full));
|
||||
await fx.WaitForAsync(again.Id, JobState.Done);
|
||||
}
|
||||
Assert.Equal(light.Id, (await SingleLightJobAsync(fx))?.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnImportQueuesLightAnalysisOfTheSequencesItFilled()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var card = context.CreateTempDirectory("card");
|
||||
Photos.WriteSeries(Path.Combine(card, "DCIM", "100CANON"), ArchiveFixture.Start, 10);
|
||||
var plan = await fx.Archive.Service.PlanImportAsync(fx.Archive.Archive.Id, card, new ImportOptions(), null, null, fx.Ct);
|
||||
await fx.StartEngineAsync(withArchive: true);
|
||||
|
||||
var import = await fx.Engine.EnqueueAsync(ArchiveJobs.Import(fx.Archive.Archive, plan, null), createdBy: Guid.CreateVersion7(), cancellationToken: fx.Ct);
|
||||
await fx.WaitForAsync(import.Id, JobState.Done);
|
||||
var light = Assert.NotNull(await SingleLightJobAsync(fx));
|
||||
await fx.WaitForAsync(light.Id, JobState.Done);
|
||||
|
||||
var sequenceId = await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Archive.Id, plan.Sessions.Single().SessionKey, fx.Ct);
|
||||
Assert.SequenceEqual([Assert.NotNull(sequenceId)], light.TargetIds);
|
||||
Assert.Equal(import.CreatedBy, light.CreatedBy);
|
||||
Assert.Equal(JobPriority.Background, light.Priority);
|
||||
Assert.True((await fx.Db.Sequences.GetAsync(sequenceId.Value, fx.Ct))!.Status.HasFlag(SequenceStatus.AnalyzedLight), "analysed");
|
||||
}
|
||||
|
||||
private static async Task<Job?> SingleLightJobAsync(ProcessingFixture fx) =>
|
||||
(await fx.Db.Jobs.ListAsync(null, JobKind.LightAnalyse, cancellationToken: fx.Ct)).Items.SingleOrDefault();
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Processing.Jobs;
|
||||
using Titano.Data.Repositories;
|
||||
using Titano.Testing;
|
||||
|
||||
@@ -105,6 +106,55 @@ public sealed class AnalysisJobTests(TestContext context)
|
||||
Assert.Contains(Loc.L("Advisor.Log.Presets", string.Empty), done.LogTail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceThatFailsDoesNotStopTheOthersAndARetryRedoesOnlyIt()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var a = await fx.AddAsync(Flickering(10), "A");
|
||||
var b = await fx.AddAsync(Flickering(10), "B");
|
||||
var c = await fx.AddAsync(Flickering(10), "C");
|
||||
// B's sidecar is gone for a while: its status cannot be recorded.
|
||||
var sidecar = fx.Folder(b).ManifestPath;
|
||||
var saved = await File.ReadAllBytesAsync(sidecar, fx.Ct);
|
||||
File.Delete(sidecar);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([a.Id, b.Id, c.Id]));
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.Equal(Loc.L("Errors.Analysis.Failed", 1, 3), failed.Error);
|
||||
Assert.Equal("3;1", failed.Checkpoint);
|
||||
Assert.SequenceEqual([true, false, true], await AnalysedAsync(fx, a, b, c));
|
||||
|
||||
await File.WriteAllBytesAsync(sidecar, saved, fx.Ct);
|
||||
await fx.Engine.ResumeAsync(job.Id, fx.Ct);
|
||||
var done = await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
Assert.SequenceEqual([true, true, true], await AnalysedAsync(fx, a, b, c));
|
||||
Assert.Equal((3L, 3L), (done.ProgressDone, done.ProgressTotal));
|
||||
// The retry analysed B alone.
|
||||
var lightOfA = Loc.L("Advisor.Log.LightDone", a.DisplayTitle, 10, 0).Split(',')[0];
|
||||
Assert.Equal(1, done.LogTail!.Split('\n').Count(line => line.Contains(lightOfA, StringComparison.Ordinal)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnalysisCheckpointsKeepTheFailedTargets()
|
||||
{
|
||||
Assert.Equal("3", AnalyseJobHandler.Format(3, []));
|
||||
Assert.Equal("4;0,2", AnalyseJobHandler.Format(4, [2, 0]));
|
||||
var (next, retry) = AnalyseJobHandler.Parse("4;0,2", 5);
|
||||
Assert.Equal(4, next);
|
||||
Assert.SequenceEqual([0, 2], retry);
|
||||
Assert.Equal(2, AnalyseJobHandler.Parse("2", 5).Next);
|
||||
// Anything else starts over: no checkpoint, beyond the targets, a failed target not yet reached, garbage.
|
||||
foreach (var text in new[] { null, "6", "2;3", "2;x", "a" }) Assert.Equal(0, AnalyseJobHandler.Parse(text, 5).Next);
|
||||
}
|
||||
|
||||
private static async Task<List<bool>> AnalysedAsync(ProcessingFixture fx, params Sequence[] sequences)
|
||||
{
|
||||
var analysed = new List<bool>();
|
||||
foreach (var s in sequences) analysed.Add((await fx.Db.Sequences.GetAsync(s.Id, fx.Ct))!.Status.HasFlag(SequenceStatus.AnalyzedLight));
|
||||
return analysed;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LightAnalysisAfterNewFramesDropsTheStaleDeepStatus()
|
||||
{
|
||||
|
||||
@@ -45,10 +45,10 @@ internal sealed class ProcessingFixture : IAsyncDisposable
|
||||
|
||||
public static async Task<ProcessingFixture> CreateAsync(TestContext context) => new(await ArchiveFixture.CreateAsync(context), new GateDecoder());
|
||||
|
||||
/// <summary>A started engine with the processing handlers (one worker, fast checkpoints).</summary>
|
||||
public async Task<JobEngine> StartEngineAsync()
|
||||
/// <summary>A started engine with the processing handlers, and the archive's when asked (one worker, fast checkpoints).</summary>
|
||||
public async Task<JobEngine> StartEngineAsync(bool withArchive = false)
|
||||
{
|
||||
_engine = new JobEngine(Db, Processing.CreateJobHandlers(),
|
||||
_engine = new JobEngine(Db, [.. withArchive ? Archive.Service.CreateJobHandlers() : [], .. Processing.CreateJobHandlers()],
|
||||
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
|
||||
await _engine.StartAsync(Ct);
|
||||
return _engine;
|
||||
@@ -61,6 +61,15 @@ internal sealed class ProcessingFixture : IAsyncDisposable
|
||||
/// <summary>Writes frames <paramref name="first"/>… of <paramref name="sequence"/> as JPEGs with their Exif into
|
||||
/// <paramref name="folder"/> (adopted in place) and indexes the archive.</summary>
|
||||
public async Task<Sequence> AddAsync(SyntheticSequence sequence, string folder = "Synthetic", int first = 0)
|
||||
{
|
||||
Write(sequence, folder, first);
|
||||
await Archive.ScanAsync(ScanMode.Full);
|
||||
var location = (await Db.Sequences.ListLocationsAsync(Archive.Archive.Id, Ct)).Single(l => l.Folder == folder);
|
||||
return (await Db.Sequences.GetAsync(location.Id, Ct))!;
|
||||
}
|
||||
|
||||
/// <summary>Writes frames <paramref name="first"/>… of <paramref name="sequence"/> as JPEGs with their Exif into <paramref name="folder"/>.</summary>
|
||||
public void Write(SyntheticSequence sequence, string folder = "Synthetic", int first = 0)
|
||||
{
|
||||
var directory = Path.Combine(Archive.Paths.Root, folder);
|
||||
Directory.CreateDirectory(directory);
|
||||
@@ -70,9 +79,6 @@ internal sealed class ProcessingFixture : IAsyncDisposable
|
||||
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i]);
|
||||
File.WriteAllBytes(Path.Combine(directory, FileName(i)), JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 95, App1Segments = [exif[4..]] }));
|
||||
}
|
||||
await Archive.ScanAsync(ScanMode.Full);
|
||||
var location = (await Db.Sequences.ListLocationsAsync(Archive.Archive.Id, Ct)).Single(l => l.Folder == folder);
|
||||
return (await Db.Sequences.GetAsync(location.Id, Ct))!;
|
||||
}
|
||||
|
||||
public static string FileName(int index) => $"IMG_{index + 1:0000}.JPG";
|
||||
|
||||
@@ -6,6 +6,7 @@ using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Jobs;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Testing;
|
||||
|
||||
@@ -145,6 +146,37 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.Count(2, await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerTakesOnlyTheRendersItsManagedEncodersProduce()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var server = new ProcessingService(fx.Db, new ProcessingOptions { Host = EncoderHost.Server });
|
||||
var handler = Assert.NotNull(server.CreateJobHandlers().Single(h => h.Kind == JobKind.Render) as ISelectiveJobHandler);
|
||||
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Synthetic" };
|
||||
bool Accepts(ExportSettings export) =>
|
||||
handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = ProcessingJobs.Render(sequence, export, 96, 64).ParametersJson });
|
||||
|
||||
Assert.True(Accepts(Mjpeg with { Batch = ["png-sequence", "gif-preview"] }), "managed outputs only");
|
||||
Assert.False(Accepts(new ExportSettings { Preset = new Auto<string>().WithManual("4k-hevc") }), "HEVC needs a render node");
|
||||
Assert.False(Accepts(Mjpeg with { Batch = ["1080p-h264"] }), "one MP4 in the batch");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = "{}" }), "unreadable: fails with its reason");
|
||||
|
||||
var client = new ProcessingService(fx.Db).CreateJobHandlers().Single(h => h.Kind == JobKind.Render);
|
||||
Assert.False(client is ISelectiveJobHandler, "a client renders whatever it is given");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABatchForAServerBecomesOneJobPerPreset()
|
||||
{
|
||||
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Synthetic", Title = "Roof" };
|
||||
var jobs = ProcessingJobs.RenderEach(sequence, Mjpeg with { Batch = ["mjpeg-avi", "gif-preview", "GIF-preview", "4k-hevc"] }, 96, 64);
|
||||
var parameters = jobs.Select(j => System.Text.Json.JsonSerializer.Deserialize(j.ParametersJson!, Titano.Protocol.ProtocolJson.Default.RenderJobParameters)!).ToList();
|
||||
Assert.SequenceEqual(["mjpeg", "gif", "hevc"], parameters.Select(p => p.Codec));
|
||||
Assert.True(jobs.All(j => j.Kind == JobKind.Render && j.Targets.SequenceEqual([sequence.Id])), "render jobs of the sequence");
|
||||
Assert.True(parameters.All(p => ProcessingJobs.ReadExport(p.PresetJson).Batch.Count == 0), "no job carries a batch");
|
||||
Assert.Equal((3840, 2160), (parameters[2].Width, parameters[2].Height));
|
||||
}
|
||||
|
||||
private static List<string> Entries(string folder) =>
|
||||
Directory.Exists(folder) ? [.. Directory.EnumerateFileSystemEntries(folder).Select(e => Path.GetFileName(e)).Order(StringComparer.Ordinal)] : [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user