using System.Diagnostics.CodeAnalysis; using API.Schema.LibraryContext; using API.Schema.LibraryContext.LibraryConnectors; using Microsoft.EntityFrameworkCore; namespace API.Workers; public class RefreshLibrariesWorker(IEnumerable? dependsOn = null) : BaseWorkerWithContexts(dependsOn) { public static DateTime LastRefresh { get; set; } = DateTime.UnixEpoch; [SuppressMessage("ReSharper", "InconsistentNaming")] private LibraryContext LibraryContext = null!; protected override void SetContexts(IServiceScope serviceScope) { LibraryContext = GetContext(serviceScope); } protected override async Task DoWorkInternal() { Log.Debug("Refreshing libraries..."); LastRefresh = DateTime.UtcNow; List libraries = await LibraryContext.LibraryConnectors.ToListAsync(CancellationToken); foreach (LibraryConnector connector in libraries) await connector.UpdateLibrary(CancellationToken); Log.Debug("Libraries Refreshed..."); return []; } } public enum LibraryRefreshSetting { /// /// Refresh Libraries after all Manga are downloaded /// AfterAllFinished, /// /// Refresh Libraries after a Manga is downloaded /// AfterMangaFinished, /// /// Refresh Libraries after every download /// AfterEveryChapter, /// /// Refresh Libraries while downloading chapters, every x minutes /// WhileDownloading }