using Chronos.Core.Imaging.Decoders; using Chronos.Data; using Chronos.Data.Archiving; using Chronos.Data.Housekeeping; using Chronos.Data.Jobs; using Chronos.Protocol; using Chronos.Server.Configuration; using Chronos.Server.Events; namespace Chronos.Server.Storage; /// /// The archive engine behind the server (BRIEF §7, §14.4): ingest of verified uploads, lookup of proxies and /// 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 s in DI, Reorganize's /// move jobs and the convert jobs, which tell connected clients of the sequences they change or make, and check /// their space against the space volume's free bytes, ); 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 /// (, owner review 2, R10). /// public static class ArchiveModule { /// Name the server writes into the archive's lease files. public static string Owner { get; } = "server@" + Environment.MachineName; public static void Register(IServiceCollection services) { services.AddSingleton(sp => { var options = sp.GetRequiredService(); var db = sp.GetRequiredService(); var events = sp.GetRequiredService(); var volumes = sp.GetService(); // Photos the running job processes at once: the settings' value as it is when each sequence starts (owner review 1). return new ArchiveService(db, new ArchiveServiceOptions { // A Reorganize or a conversion tells connected clients of every sequence it changed or made (BRIEF §14.3). SequenceChanged = async (id, change, ct) => { if (await db.Sequences.GetAsync(id, ct) is { } sequence) events.Publish(new SequenceChangedEvent(id, change, 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 // (R2: the space path's volume) and the volume the archive's folders are on, which takes every byte it stages // and files (on Unraid the cache, until the mover runs). FreeSpace = volumes is null ? null : volumes.WritableFree, Owner = Owner, ImagesAfterScan = true, Parallelism = () => options.Parallelism, CleanupSteps = [.. sp.GetServices()], // Next to the index in the data folder, where the daily backups always went. BackupDirectory = Path.Combine(options.DataPath, DatabaseBackups.DirectoryName), }); }); services.AddSingleton(sp => sp.GetRequiredService().Ingest); services.AddSingleton(sp => sp.GetRequiredService()); services.AddSingleton(); } }