feat(data): archive services, ingest and job handlers
ArchiveService facade over indexer (scan, adopt, rebuild), ArchiveIngest (IArchiveIngest with per-sequence group commit, leases and a write-ahead journal), verifier, maintenance (duplicates, orphans, cleanup), mass rename with resumable journal, thumbnails/proxies and card import; job handlers for scan, rebuild, verify, import, thumbs, proxies and maintenance with checkpoints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
23 files changed
+3161
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using System.Globalization;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Jobs;
|
||||
|
||||
namespace Titano.Data.Archiving.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="JobKind.Thumbs"/> and <see cref="JobKind.Proxies"/> over the target sequences. Progress counts
|
||||
/// sequences; checkpoint: <c>sequence:frame</c>.
|
||||
/// </summary>
|
||||
internal sealed class ImageJobHandler(TitanoDatabase db, ArchiveImages images, JobKind kind) : IJobHandler
|
||||
{
|
||||
public JobKind Kind => kind;
|
||||
|
||||
public async Task RunAsync(JobContext context)
|
||||
{
|
||||
var force = ArchiveJobJson.Read(context.Job, ArchiveJobJson.Default.ImageJobParameters, new ImageJobParameters(false)).Force;
|
||||
var (first, firstFrame) = Parse(context.Checkpoint);
|
||||
var targets = context.Job.TargetIds;
|
||||
for (var s = first; s < targets.Count; s++)
|
||||
{
|
||||
context.Cancellation.ThrowIfCancellationRequested();
|
||||
if (await db.Sequences.GetAsync(targets[s], context.Cancellation).ConfigureAwait(false) is not { } sequence
|
||||
|| await db.Archives.GetAsync(sequence.ArchiveId, context.Cancellation).ConfigureAwait(false) is not { } archive)
|
||||
{
|
||||
context.Log(Loc.L("Archive.Log.SequenceMissing", targets[s]));
|
||||
continue;
|
||||
}
|
||||
var index = s;
|
||||
ValueTask Checkpoint(int nextFrame, int frames) =>
|
||||
context.CheckpointAsync(string.Create(CultureInfo.InvariantCulture, $"{index}:{nextFrame}"), index, targets.Count);
|
||||
var start = s == first ? firstFrame : 0;
|
||||
var result = kind == JobKind.Thumbs
|
||||
? await images.BuildThumbnailsAsync(archive, sequence, force, start, Checkpoint, context.Cancellation).ConfigureAwait(false)
|
||||
: await images.BuildProxiesAsync(archive, sequence, force, start, Checkpoint, context.Cancellation).ConfigureAwait(false);
|
||||
context.Log(Loc.L("Archive.Log.ImagesDone", sequence.DisplayTitle, result.Built, result.Reused, result.Undecodable));
|
||||
await context.CheckpointAsync(string.Create(CultureInfo.InvariantCulture, $"{s + 1}:0"), s + 1, targets.Count).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static (int Sequence, int Frame) Parse(string? checkpoint)
|
||||
{
|
||||
var parts = checkpoint?.Split(':');
|
||||
return parts is [var s, var f]
|
||||
&& int.TryParse(s, NumberStyles.None, CultureInfo.InvariantCulture, out var sequence)
|
||||
&& int.TryParse(f, NumberStyles.None, CultureInfo.InvariantCulture, out var frame)
|
||||
? (sequence, frame)
|
||||
: (0, 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user