mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 09:54:16 +02:00
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using API.Schema.MangaContext;
|
|
using API.Schema.MangaContext.MetadataFetchers;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace API.Workers;
|
|
|
|
public class UpdateMetadataWorker(TimeSpan? interval = null, IEnumerable<BaseWorker>? dependsOn = null)
|
|
: BaseWorkerWithContext<MangaContext>(dependsOn), IPeriodic
|
|
{
|
|
|
|
public DateTime LastExecution { get; set; } = DateTime.UtcNow;
|
|
public TimeSpan Interval { get; set; } = interval ?? TimeSpan.FromHours(12);
|
|
|
|
protected override BaseWorker[] DoWorkInternal()
|
|
{
|
|
IQueryable<string> mangaIds = DbContext.MangaConnectorToManga
|
|
.Where(m => m.UseForDownload)
|
|
.Select(m => m.ObjId);
|
|
IQueryable<MetadataEntry> metadataEntriesToUpdate = DbContext.MetadataEntries
|
|
.Include(e => e.MetadataFetcher)
|
|
.Where(e =>
|
|
mangaIds.Any(id => id == e.MangaId));
|
|
|
|
foreach (MetadataEntry metadataEntry in metadataEntriesToUpdate)
|
|
metadataEntry.MetadataFetcher.UpdateMetadata(metadataEntry, DbContext);
|
|
|
|
DbContext.Sync();
|
|
|
|
return [];
|
|
}
|
|
} |