using System.Diagnostics.CodeAnalysis;
using API.Schema.MangaContext;
using API.Workers.MangaDownloadWorkers;
using Microsoft.EntityFrameworkCore;
namespace API.Workers.PeriodicWorkers;
///
/// Creates Workers to update covers for Manga
///
///
///
public class UpdateCoversWorker(TimeSpan? interval = null, IEnumerable? dependsOn = null)
: BaseWorkerWithContexts(dependsOn), IPeriodic
{
public DateTime LastExecution { get; set; } = DateTime.UnixEpoch;
public TimeSpan Interval { get; set; } = interval ?? TimeSpan.FromHours(6);
[SuppressMessage("ReSharper", "InconsistentNaming")]
private MangaContext MangaContext = null!;
protected override void SetContexts(IServiceScope serviceScope)
{
MangaContext = GetContext(serviceScope);
}
protected override async Task DoWorkInternal()
{
List> manga = await MangaContext.MangaConnectorToManga.Where(mcId => mcId.UseForDownload).ToListAsync(CancellationToken);
List newWorkers = manga.Select(m => new DownloadCoverFromMangaconnectorWorker(m)).ToList();
return newWorkers.ToArray();
}
}