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
34 lines
1.7 KiB
C#
34 lines
1.7 KiB
C#
using System.Globalization;
|
|
using System.Text.Json;
|
|
using Titano.Core.Import;
|
|
using Titano.Core.Localization;
|
|
using Titano.Core.Model;
|
|
using Titano.Data.Jobs;
|
|
|
|
namespace Titano.Data.Archiving.Jobs;
|
|
|
|
/// <summary>
|
|
/// <see cref="JobKind.Import"/>: executes the confirmed plan in its parameters; progress in bytes. Checkpoint: the
|
|
/// number of plan items done. A removed card fails the job at a batch boundary; resuming it after re-insertion
|
|
/// continues there.
|
|
/// </summary>
|
|
internal sealed class ImportJobHandler(ImportService imports) : IJobHandler
|
|
{
|
|
public JobKind Kind => JobKind.Import;
|
|
|
|
public async Task RunAsync(JobContext context)
|
|
{
|
|
var parameters = (context.Job.ParametersJson is { Length: > 0 } json ? JsonSerializer.Deserialize(json, ArchiveJobJson.Default.ImportJobParameters) : null)
|
|
?? throw new InvalidOperationException($"Import job {context.Job.Id} has no plan.");
|
|
var start = int.TryParse(context.Checkpoint, NumberStyles.None, CultureInfo.InvariantCulture, out var next) ? next : 0;
|
|
var final = await imports.ExecuteAsync(parameters, context.Job.Id, start, async batch =>
|
|
{
|
|
foreach (var failed in batch.Results.Where(r => r.Status == ImportItemStatus.Failed))
|
|
context.Log(Loc.L("Archive.Log.ImportFailed", failed.Item.SourcePath, failed.Error));
|
|
await context.CheckpointAsync(batch.NextItem.ToString(CultureInfo.InvariantCulture), batch.Progress.BytesDone, batch.Progress.BytesTotal)
|
|
.ConfigureAwait(false);
|
|
}, p => context.ReportAsync(p.BytesDone, p.BytesTotal, p.Current), context.Cancellation).ConfigureAwait(false);
|
|
context.Log(Loc.L("Archive.Log.ImportDone", final.Copied, final.Skipped, final.Failed));
|
|
}
|
|
}
|